* [PATCH 0/2] selftests/mm: Add -Wunreachable-code and fix warnings
@ 2025-09-12 12:30 Muhammad Usama Anjum
2025-09-12 12:30 ` [PATCH 1/2] " Muhammad Usama Anjum
2025-09-12 12:30 ` [PATCH 2/2] selftests/mm: protection_keys: Fix dead code Muhammad Usama Anjum
0 siblings, 2 replies; 6+ messages in thread
From: Muhammad Usama Anjum @ 2025-09-12 12:30 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Jason Gunthorpe,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, linux-mm, linux-kselftest,
linux-kernel
Cc: Muhammad Usama Anjum, kernel
This series is trimmed down version of previous more generic series[1].
In this new series, only -wunreachable-code flag is being added and dead
code is being removed from generated warnings.
[1] https://lore.kernel.org/all/20250822082145.4145617-1-usama.anjum@collabora.com
Muhammad Usama Anjum (2):
selftests/mm: Add -Wunreachable-code and fix warnings
selftests/mm: protection_keys: Fix dead code
tools/testing/selftests/mm/Makefile | 1 +
tools/testing/selftests/mm/hmm-tests.c | 5 ++---
tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +-
tools/testing/selftests/mm/protection_keys.c | 4 +---
tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
5 files changed, 6 insertions(+), 8 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] selftests/mm: Add -Wunreachable-code and fix warnings
2025-09-12 12:30 [PATCH 0/2] selftests/mm: Add -Wunreachable-code and fix warnings Muhammad Usama Anjum
@ 2025-09-12 12:30 ` Muhammad Usama Anjum
2025-09-12 12:35 ` David Hildenbrand
2025-09-15 15:43 ` Zi Yan
2025-09-12 12:30 ` [PATCH 2/2] selftests/mm: protection_keys: Fix dead code Muhammad Usama Anjum
1 sibling, 2 replies; 6+ messages in thread
From: Muhammad Usama Anjum @ 2025-09-12 12:30 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Jason Gunthorpe,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, linux-mm, linux-kselftest,
linux-kernel
Cc: Muhammad Usama Anjum, kernel, Sidhartha Kumar, Kevin Brodsky
Enable -Wunreachable-code flag to catch dead code and fix them.
1. Remove the dead code and write a comment instead:
hmm-tests.c:2033:3: warning: code will never be executed
[-Wunreachable-code]
perror("Should not reach this\n");
^~~~~~
2. ksft_exit_fail_msg() calls exit(). So cleanup isn't done. Replace it
with ksft_print_msg().
split_huge_page_test.c:301:3: warning: code will never be executed
[-Wunreachable-code]
goto cleanup;
^~~~~~~~~~~~
3. Remove duplicate inline.
pkey_sighandler_tests.c:44:15: warning: duplicate 'inline' declaration
specifier [-Wduplicate-decl-specifier]
static inline __always_inline
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/mm/Makefile | 1 +
tools/testing/selftests/mm/hmm-tests.c | 5 ++---
tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +-
tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index 5a1dee50b8987..eaf9312097f7b 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -34,6 +34,7 @@ endif
MAKEFLAGS += --no-builtin-rules
CFLAGS = -Wall -O2 -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
+CFLAGS += -Wunreachable-code
LDLIBS = -lrt -lpthread -lm
# Some distributions (such as Ubuntu) configure GCC so that _FORTIFY_SOURCE is
diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
index 1325de70f44fc..25045536f4707 100644
--- a/tools/testing/selftests/mm/hmm-tests.c
+++ b/tools/testing/selftests/mm/hmm-tests.c
@@ -2030,11 +2030,10 @@ TEST_F(hmm, hmm_cow_in_device)
if (pid == -1)
ASSERT_EQ(pid, 0);
if (!pid) {
- /* Child process waitd for SIGTERM from the parent. */
+ /* Child process waits for SIGTERM from the parent. */
while (1) {
}
- perror("Should not reach this\n");
- exit(0);
+ /* Should not reach this */
}
/* Parent process writes to COW pages(s) and gets a
* new copy in system. In case of device private pages,
diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/testing/selftests/mm/pkey_sighandler_tests.c
index b5e076a564c95..302fef54049c8 100644
--- a/tools/testing/selftests/mm/pkey_sighandler_tests.c
+++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c
@@ -41,7 +41,7 @@ static siginfo_t siginfo = {0};
* syscall will attempt to access the PLT in order to call a library function
* which is protected by MPK 0 which we don't have access to.
*/
-static inline __always_inline
+static __always_inline
long syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
{
unsigned long ret;
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 7731191cc8e9b..743af3c051905 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -510,7 +510,7 @@ static void split_file_backed_thp(int order)
status = snprintf(testfile, INPUT_MAX, "%s/thp_file", tmpfs_loc);
if (status >= INPUT_MAX) {
- ksft_exit_fail_msg("Fail to create file-backed THP split testing file\n");
+ ksft_print_msg("Fail to create file-backed THP split testing file\n");
goto cleanup;
}
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] selftests/mm: protection_keys: Fix dead code
2025-09-12 12:30 [PATCH 0/2] selftests/mm: Add -Wunreachable-code and fix warnings Muhammad Usama Anjum
2025-09-12 12:30 ` [PATCH 1/2] " Muhammad Usama Anjum
@ 2025-09-12 12:30 ` Muhammad Usama Anjum
2025-09-15 15:43 ` Zi Yan
1 sibling, 1 reply; 6+ messages in thread
From: Muhammad Usama Anjum @ 2025-09-12 12:30 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Jason Gunthorpe,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, linux-mm, linux-kselftest,
linux-kernel
Cc: Muhammad Usama Anjum, kernel, Sidhartha Kumar
The while loop doesn't execute and following warning gets generated:
protection_keys.c:561:15: warning: code will never be executed
[-Wunreachable-code]
int rpkey = alloc_random_pkey();
Let's enable the while loop such that it gets executed nr_iterations
times. Simplify the code a bit as well.
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/mm/protection_keys.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
index 23ebec367015f..6281d4c61b50e 100644
--- a/tools/testing/selftests/mm/protection_keys.c
+++ b/tools/testing/selftests/mm/protection_keys.c
@@ -557,13 +557,11 @@ int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
int nr_iterations = random() % 100;
int ret;
- while (0) {
+ while (nr_iterations-- >= 0) {
int rpkey = alloc_random_pkey();
ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey);
dprintf1("sys_mprotect_pkey(%p, %zx, prot=0x%lx, pkey=%ld) ret: %d\n",
ptr, size, orig_prot, pkey, ret);
- if (nr_iterations-- < 0)
- break;
dprintf1("%s()::%d, ret: %d pkey_reg: 0x%016llx"
" shadow: 0x%016llx\n",
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] selftests/mm: Add -Wunreachable-code and fix warnings
2025-09-12 12:30 ` [PATCH 1/2] " Muhammad Usama Anjum
@ 2025-09-12 12:35 ` David Hildenbrand
2025-09-15 15:43 ` Zi Yan
1 sibling, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2025-09-12 12:35 UTC (permalink / raw)
To: Muhammad Usama Anjum, Andrew Morton, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Jason Gunthorpe,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, linux-mm, linux-kselftest,
linux-kernel
Cc: kernel, Sidhartha Kumar, Kevin Brodsky
On 12.09.25 14:30, Muhammad Usama Anjum wrote:
> Enable -Wunreachable-code flag to catch dead code and fix them.
>
> 1. Remove the dead code and write a comment instead:
> hmm-tests.c:2033:3: warning: code will never be executed
> [-Wunreachable-code]
> perror("Should not reach this\n");
> ^~~~~~
>
> 2. ksft_exit_fail_msg() calls exit(). So cleanup isn't done. Replace it
> with ksft_print_msg().
> split_huge_page_test.c:301:3: warning: code will never be executed
> [-Wunreachable-code]
> goto cleanup;
> ^~~~~~~~~~~~
>
> 3. Remove duplicate inline.
> pkey_sighandler_tests.c:44:15: warning: duplicate 'inline' declaration
> specifier [-Wduplicate-decl-specifier]
> static inline __always_inline
>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] selftests/mm: protection_keys: Fix dead code
2025-09-12 12:30 ` [PATCH 2/2] selftests/mm: protection_keys: Fix dead code Muhammad Usama Anjum
@ 2025-09-15 15:43 ` Zi Yan
0 siblings, 0 replies; 6+ messages in thread
From: Zi Yan @ 2025-09-15 15:43 UTC (permalink / raw)
To: Muhammad Usama Anjum
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Jason Gunthorpe,
Leon Romanovsky, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, linux-mm, linux-kselftest, linux-kernel,
kernel, Sidhartha Kumar
On 12 Sep 2025, at 8:30, Muhammad Usama Anjum wrote:
> The while loop doesn't execute and following warning gets generated:
>
> protection_keys.c:561:15: warning: code will never be executed
> [-Wunreachable-code]
> int rpkey = alloc_random_pkey();
>
> Let's enable the while loop such that it gets executed nr_iterations
> times. Simplify the code a bit as well.
>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> tools/testing/selftests/mm/protection_keys.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] selftests/mm: Add -Wunreachable-code and fix warnings
2025-09-12 12:30 ` [PATCH 1/2] " Muhammad Usama Anjum
2025-09-12 12:35 ` David Hildenbrand
@ 2025-09-15 15:43 ` Zi Yan
1 sibling, 0 replies; 6+ messages in thread
From: Zi Yan @ 2025-09-15 15:43 UTC (permalink / raw)
To: Muhammad Usama Anjum
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Jason Gunthorpe,
Leon Romanovsky, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, linux-mm, linux-kselftest, linux-kernel,
kernel, Sidhartha Kumar, Kevin Brodsky
On 12 Sep 2025, at 8:30, Muhammad Usama Anjum wrote:
> Enable -Wunreachable-code flag to catch dead code and fix them.
>
> 1. Remove the dead code and write a comment instead:
> hmm-tests.c:2033:3: warning: code will never be executed
> [-Wunreachable-code]
> perror("Should not reach this\n");
> ^~~~~~
>
> 2. ksft_exit_fail_msg() calls exit(). So cleanup isn't done. Replace it
> with ksft_print_msg().
> split_huge_page_test.c:301:3: warning: code will never be executed
> [-Wunreachable-code]
> goto cleanup;
> ^~~~~~~~~~~~
>
> 3. Remove duplicate inline.
> pkey_sighandler_tests.c:44:15: warning: duplicate 'inline' declaration
> specifier [-Wduplicate-decl-specifier]
> static inline __always_inline
>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> tools/testing/selftests/mm/Makefile | 1 +
> tools/testing/selftests/mm/hmm-tests.c | 5 ++---
> tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +-
> tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
> 4 files changed, 5 insertions(+), 5 deletions(-)
>
LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-15 15:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-12 12:30 [PATCH 0/2] selftests/mm: Add -Wunreachable-code and fix warnings Muhammad Usama Anjum
2025-09-12 12:30 ` [PATCH 1/2] " Muhammad Usama Anjum
2025-09-12 12:35 ` David Hildenbrand
2025-09-15 15:43 ` Zi Yan
2025-09-12 12:30 ` [PATCH 2/2] selftests/mm: protection_keys: Fix dead code Muhammad Usama Anjum
2025-09-15 15:43 ` Zi Yan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox