Skip to contentSkip to conversation

scripts: ipe: polgen: remove redundant close and error exit path

PATCH In review Colin Ian King 2 participants 2 messages Oct 31, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: ipe: polgen: remove redundant close and error exit path

Currently if an fopen fails the error exit path is via code that checks if fp is not null and closes the file, however, fp is null so this check and close is redundant. Since the only use of the err exit label is on the fopen check, remove it and replace the code with a simple return of errno. Also remove variable rc since it's no longer required.

---
 scripts/ipe/polgen/polgen.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
scripts/ipe/polgen/polgen.c +2 -10
index c6283b3ff006..01134cf895d0 100644
@@ -61,15 +61,12 @@ static int policy_to_buffer(const char *pathname, char **buffer, size_t *size)
 
 static int write_boot_policy(const char *pathname, const char *buf, size_t size)
 {
-	int rc = 0;
 	FILE *fd;
 	size_t i;
 
 	fd = fopen(pathname, "w");
-	if (!fd) {
-		rc = errno;
-		goto err;
-	}
+	if (!fd)
+		return errno;
 
 	fprintf(fd, "/* This file is automatically generated.");
 	fprintf(fd, " Do not edit. */\n");
@@ -113,11 +110,6 @@ static int write_boot_policy(const char *pathname, const char *buf, size_t size)
 	fclose(fd);
 
 	return 0;
-
-err:
-	if (fd)
-		fclose(fd);
-	return rc;
 }
 
 int main(int argc, const char *const argv[])
Signature · 1 line
2.39.5
maintainer Acked-by on v1 1/1
#1 lore raw

Thanks, I will pull this into my tree.

-Fan

Quoted 51 lines · Colin Ian King

Currently if an fopen fails the error exit path is via code that checks if fp is not null and closes the file, however, fp is null so this check and close is redundant. Since the only use of the err exit label is on the fopen check, remove it and replace the code with a simple return of errno. Also remove variable rc since it's no longer required.

---
 scripts/ipe/polgen/polgen.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
scripts/ipe/polgen/polgen.c +2 -11
index c6283b3ff006..01134cf895d0 100644
@@ -61,15 +61,12 @@ static int policy_to_buffer(const char *pathname, char **buffer, size_t *size)
 
 static int write_boot_policy(const char *pathname, const char *buf, size_t size)
 {
-       int rc = 0;
        FILE *fd;
        size_t i;
 
        fd = fopen(pathname, "w");
-       if (!fd) {
-               rc = errno;
-               goto err;
-       }
+       if (!fd)
+               return errno;
 
        fprintf(fd, "/* This file is automatically generated.");
        fprintf(fd, " Do not edit. */\n");
@@ -113,11 +110,6 @@ static int write_boot_policy(const char *pathname, const char *buf, size_t size)
        fclose(fd);
 
        return 0;
-
-err:
-       if (fd)
-               fclose(fd);
-       return rc;
 }
 
 int main(int argc, const char *const argv[])
--

2.39.5