]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/mm: protection_keys: fix dead code
authorMuhammad Usama Anjum <usama.anjum@collabora.com>
Thu, 31 Jul 2025 16:01:26 +0000 (21:01 +0500)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 18 Aug 2025 05:08:25 +0000 (22:08 -0700)
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.

Link: https://lkml.kernel.org/r/20250731160132.1795351-3-usama.anjum@collabora.com
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/protection_keys.c

index 23ebec367015fd195eb9feabe252d55009aa839a..6281d4c61b50e4a5fe0e290fcae07c5c0ddaba0f 100644 (file)
@@ -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",