[PATCH] depmod: Dont use errno unconditionally

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fopen() will not reset errno if it succeeds so we should
make sure that we only use errno in error cases.

Also fix the diagnostic messages to not use strerror
when there is no error since strerror will not return
anything useful in this case

Signed-off-by: Khem Raj <raj.khem@xxxxxxxxx>
---
 tools/kmod-depmod.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/tools/kmod-depmod.c b/tools/kmod-depmod.c
index 0721daf..01bca2a 100644
--- a/tools/kmod-depmod.c
+++ b/tools/kmod-depmod.c
@@ -941,7 +941,7 @@ static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files,
 	}
 
 	closedir(d);
-	DBG("parsed configuration files from %s: %s\n", path, strerror(-err));
+	DBG("parsed configuration files from %s\n", path);
 	return err;
 }
 
@@ -2293,13 +2293,15 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
 	char line[10240];
 	FILE *fp;
 	unsigned int linenum = 0;
-	int err;
+	int err = 0;
 
 	fp = fopen(filename, "r");
-	err = -errno;
-	DBG("load symvers: %s: %s\n", filename, strerror(-err));
-	if (fp == NULL)
+	if (fp == NULL) {
+		err = -errno;
+		DBG("load symvers: %s: %s\n", filename, strerror(-err));
 		return err;
+	}
+	DBG("load symvers: %s\n", filename);
 
 	/* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */
 	while (fgets(line, sizeof(line), fp) != NULL) {
@@ -2329,7 +2331,7 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
 	}
 	depmod_add_fake_syms(depmod);
 
-	DBG("loaded symvers: %s: %s\n", filename, strerror(-err));
+	DBG("loaded symvers: %s\n", filename);
 
 	fclose(fp);
 	return err;
@@ -2342,14 +2344,15 @@ static int depmod_load_system_map(struct depmod *depmod, const char *filename)
 	char line[10240];
 	FILE *fp;
 	unsigned int linenum = 0;
-	int err;
+	int err = 0;
 
 	fp = fopen(filename, "r");
-	err = -errno;
-	DBG("load System.map: %s: %s\n", filename, strerror(-err));
-	if (fp == NULL)
+	if (fp == NULL) {
+		err = -errno;
+		DBG("load System.map: %s: %s\n", filename, strerror(-err));
 		return err;
-
+	}
+	DBG("load System.map: %s\n", filename);
 	/* eg. c0294200 R __ksymtab_devfs_alloc_devnum */
 	while (fgets(line, sizeof(line), fp) != NULL) {
 		char *p, *end;
@@ -2381,7 +2384,7 @@ static int depmod_load_system_map(struct depmod *depmod, const char *filename)
 	}
 	depmod_add_fake_syms(depmod);
 
-	DBG("loaded System.map: %s: %s\n", filename, strerror(-err));
+	DBG("loaded System.map: %s\n", filename);
 
 	fclose(fp);
 	return err;
@@ -2673,7 +2676,7 @@ static int do_depmod(int argc, char *argv[])
 	} else if (system_map != NULL) {
 		err = depmod_load_system_map(&depmod, system_map);
 		if (err < 0) {
-			CRIT("could not load %s: %s\n", module_symvers,
+			CRIT("could not load %s: %s\n", system_map,
 			     strerror(-err));
 			goto cmdline_failed;
 		}
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux