mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Ian King <colin.i.king@gmail.com>
To: Fan Wu <wufan@kernel.org>,
	Deven Bowers <deven.desai@linux.microsoft.com>,
	Paul Moore <paul@paul-moore.com>,
	linux-security-module@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH][next] scripts: ipe: polgen: remove redundant close and error exit path
Date: Thu, 31 Oct 2024 15:58:57 +0000	[thread overview]
Message-ID: <20241031155857.3262806-1-colin.i.king@gmail.com> (raw)

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.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 scripts/ipe/polgen/polgen.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/scripts/ipe/polgen/polgen.c b/scripts/ipe/polgen/polgen.c
index c6283b3ff006..01134cf895d0 100644
--- a/scripts/ipe/polgen/polgen.c
+++ b/scripts/ipe/polgen/polgen.c
@@ -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


             reply	other threads:[~2024-10-31 15:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31 15:58 Colin Ian King [this message]
2024-10-31 17:11 ` Fan Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241031155857.3262806-1-colin.i.king@gmail.com \
    --to=colin.i.king@gmail.com \
    --cc=deven.desai@linux.microsoft.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=wufan@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®