[PATCH 01/11] discover: Properly handle return values

Samuel Mendoza-Jonas sam.mj at au1.ibm.com
Thu Nov 12 15:34:31 AEDT 2015


Fixes three unchecked return values, and one missing
initialisation.
Fixes Coverity defects #30450, #30451, #30454, and #30483

Signed-off-by: Samuel Mendoza-Jonas <sam.mj at au1.ibm.com>
---
 discover/device-handler.c   | 6 ++----
 discover/ipmi.c             | 3 ++-
 discover/paths.c            | 5 +++--
 discover/platform-powerpc.c | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/discover/device-handler.c b/discover/device-handler.c
index bfe5fff..3804b34 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -1472,7 +1472,6 @@ mount_ro:
 void device_release_write(struct discover_device *dev, bool release)
 {
 	const char *fstype, *device_path;
-	int rc = 0;
 
 	if (!release)
 		return;
@@ -1495,10 +1494,9 @@ void device_release_write(struct discover_device *dev, bool release)
 		device_path = get_device_path(dev);
 	}
 
-	mount(device_path, dev->mount_path, fstype,
+	if (mount(device_path, dev->mount_path, fstype,
 			MS_RDONLY | MS_SILENT,
-			fs_parameters(dev, MS_RDONLY));
-	if (rc)
+			fs_parameters(dev, MS_RDONLY)))
 		pb_log("Failed to remount %s read-only: %s\n",
 		       device_path, strerror(errno));
 	else
diff --git a/discover/ipmi.c b/discover/ipmi.c
index 54d4e06..f59974a 100644
--- a/discover/ipmi.c
+++ b/discover/ipmi.c
@@ -183,7 +183,8 @@ int ipmi_transaction(struct ipmi *ipmi, uint8_t netfn, uint8_t cmd,
 
 out:
 	lock.l_type = F_UNLCK;
-	fcntl(ipmi->fd, F_SETLKW, &lock);
+	if (fcntl(ipmi->fd, F_SETLKW, &lock) == -1)
+		pb_log("IPMI: error unlocking IPMI device: %m\n");
 	return rc ? -1 : 0;
 }
 
diff --git a/discover/paths.c b/discover/paths.c
index 0d414eb..c25671b 100644
--- a/discover/paths.c
+++ b/discover/paths.c
@@ -220,15 +220,16 @@ static enum tftp_type check_tftp_type(void *ctx)
 	const char *argv[] = { pb_system_apps.tftp, "-V", NULL };
 	struct process *process;
 	enum tftp_type type;
+	int rc;
 
 	process = process_create(ctx);
 	process->path = pb_system_apps.tftp;
 	process->argv = argv;
 	process->keep_stdout = true;
 	process->add_stderr = true;
-	process_run_sync(process);
+	rc = process_run_sync(process);
 
-	if (!process->stdout_buf || process->stdout_len == 0) {
+	if (rc || !process->stdout_buf || process->stdout_len == 0) {
 		pb_log("Can't check TFTP client type!\n");
 		type = TFTP_TYPE_BROKEN;
 
diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 23e63c1..2a02d75 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -179,7 +179,7 @@ static int write_nvram(struct platform_powerpc *platform)
 	struct process *process;
 	struct param *param;
 	const char *argv[6];
-	int rc;
+	int rc = 0;
 
 	argv[0] = "nvram";
 	argv[1] = "--update-config";
-- 
2.6.2



More information about the Petitboot mailing list