* [PATCH][next] scripts: ipe: polgen: remove redundant close and error exit path
@ 2024-10-31 15:58 Colin Ian King
2024-10-31 17:11 ` Fan Wu
0 siblings, 1 reply; 2+ messages in thread
From: Colin Ian King @ 2024-10-31 15:58 UTC (permalink / raw)
To: Fan Wu, Deven Bowers, Paul Moore, linux-security-module
Cc: kernel-janitors, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH][next] scripts: ipe: polgen: remove redundant close and error exit path
2024-10-31 15:58 [PATCH][next] scripts: ipe: polgen: remove redundant close and error exit path Colin Ian King
@ 2024-10-31 17:11 ` Fan Wu
0 siblings, 0 replies; 2+ messages in thread
From: Fan Wu @ 2024-10-31 17:11 UTC (permalink / raw)
To: Colin Ian King
Cc: Fan Wu, Deven Bowers, Paul Moore, linux-security-module,
kernel-janitors, linux-kernel
Acked-by: Fan Wu <wufan@linux.microsoft.com>
Thanks, I will pull this into my tree.
-Fan
On Thu, Oct 31, 2024 at 8:59 AM Colin Ian King <colin.i.king@gmail.com> wrote:
>
> 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
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-31 17:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-31 15:58 [PATCH][next] scripts: ipe: polgen: remove redundant close and error exit path Colin Ian King
2024-10-31 17:11 ` Fan Wu
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®