[PATCHv2] kexec-tools: Fix unused return value warnings

Ameya Palande 2ameya at gmail.com
Sat Mar 13 07:39:10 EST 2010


From: Ameya Palande <ameya.palande at nokia.com>

This patch fixes following warning:

kexec/firmware_memmap.c: In function ‘parse_numeric_sysfs’:
kexec/firmware_memmap.c:70: error: ignoring return value of ‘fgets’, declared
with attribute warn_unused_result
kexec/firmware_memmap.c: In function ‘parse_string_sysfs’:
kexec/firmware_memmap.c:103: error: ignoring return value of ‘fgets’, declared
with attribute warn_unused_result

Difference between v1 and v2: Less indentation.

Signed-off-by: Ameya Palande <ameya.palande at nokia.com>
---
 kexec/firmware_memmap.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/kexec/firmware_memmap.c b/kexec/firmware_memmap.c
index 5a101fb..5f82a10 100644
--- a/kexec/firmware_memmap.c
+++ b/kexec/firmware_memmap.c
@@ -58,7 +58,7 @@ static unsigned long long parse_numeric_sysfs(const char *filename)
 {
 	FILE *fp;
 	char linebuffer[BUFSIZ];
-	unsigned long long retval;
+	unsigned long long retval = ULLONG_MAX;
 
 	fp = fopen(filename, "r");
 	if (!fp) {
@@ -67,12 +67,15 @@ static unsigned long long parse_numeric_sysfs(const char *filename)
 		return ULLONG_MAX;
 	}
 
-	fgets(linebuffer, BUFSIZ, fp);
+	if (!fgets(linebuffer, BUFSIZ, fp))
+		goto err;
+
 	linebuffer[BUFSIZ-1] = 0;
 
 	/* let strtoll() detect the base */
 	retval = strtoll(linebuffer, NULL, 0);
 
+err:
 	fclose(fp);
 
 	return retval;
@@ -100,7 +103,11 @@ static char *parse_string_sysfs(const char *filename)
 		return NULL;
 	}
 
-	fgets(linebuffer, BUFSIZ, fp);
+	if (!fgets(linebuffer, BUFSIZ, fp)) {
+		fclose(fp);
+		return NULL;
+	}
+
 	linebuffer[BUFSIZ-1] = 0;
 
 	/* truncate trailing newline(s) */
-- 
1.6.3.3




More information about the kexec mailing list