]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/powerpc: Fix resource leaks
authorMiaoqian Lin <linmq006@gmail.com>
Mon, 5 Dec 2022 08:44:27 +0000 (12:44 +0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jan 2023 11:07:29 +0000 (12:07 +0100)
[ Upstream commit 8f4ab7da904ab7027ccd43ddb4f0094e932a5877 ]

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>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221205084429.570654-1-linmq006@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c

index 17fb1b43c320dbe8f5f943792303bdb93bee4f1f..d6fb6f1125f94727f6ac9e8ea8ccc39733ee3021 100644 (file)
@@ -27,6 +27,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);
@@ -64,8 +65,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;