* [PATCH] selftests/powerpc: Fix resource leaks
@ 2022-12-05 8:44 Miaoqian Lin
2022-12-08 12:40 ` Michael Ellerman
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2022-12-05 8:44 UTC (permalink / raw)
To: Michael Ellerman, Nicholas Piggin, Christophe Leroy, Shuah Khan,
Miaoqian Lin, Anshuman Khandual, linuxppc-dev, linux-kselftest,
linux-kernel
In check_all_cpu_dscr_defaults, opendir() opens the directory stream.
Add missing closedir() in the error path to release it.
In check_cpu_dscr_default, open() creates an open file descriptor.
Add missing close() in the error path to release it.
Fixes: ebd5858c904b ("selftests/powerpc: Add test for all DSCR sysfs interfaces")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
index fbbdffdb2e5d..f20d1c166d1e 100644
--- a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
+++ b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
@@ -24,6 +24,7 @@ static int check_cpu_dscr_default(char *file, unsigned long val)
rc = read(fd, buf, sizeof(buf));
if (rc == -1) {
perror("read() failed");
+ close(fd);
return 1;
}
close(fd);
@@ -65,8 +66,10 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
if (access(file, F_OK))
continue;
- if (check_cpu_dscr_default(file, val))
+ if (check_cpu_dscr_default(file, val)) {
+ closedir(sysfs);
return 1;
+ }
}
closedir(sysfs);
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/powerpc: Fix resource leaks
2022-12-05 8:44 [PATCH] selftests/powerpc: Fix resource leaks Miaoqian Lin
@ 2022-12-08 12:40 ` Michael Ellerman
0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2022-12-08 12:40 UTC (permalink / raw)
To: Nicholas Piggin, linux-kselftest, Christophe Leroy,
Michael Ellerman, Shuah Khan, linuxppc-dev, Miaoqian Lin,
Anshuman Khandual, linux-kernel
On Mon, 5 Dec 2022 12:44:27 +0400, Miaoqian Lin wrote:
> In check_all_cpu_dscr_defaults, opendir() opens the directory stream.
> Add missing closedir() in the error path to release it.
>
> In check_cpu_dscr_default, open() creates an open file descriptor.
> Add missing close() in the error path to release it.
>
>
> [...]
Applied to powerpc/next.
[1/1] selftests/powerpc: Fix resource leaks
https://git.kernel.org/powerpc/c/8f4ab7da904ab7027ccd43ddb4f0094e932a5877
cheers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-08 12:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-05 8:44 [PATCH] selftests/powerpc: Fix resource leaks Miaoqian Lin
2022-12-08 12:40 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).