Message ID | 20250109173842.1142376-2-usama.anjum@collabora.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | selftest/mm: Remove warnings found by adding compiler flags | expand |
On Thu, Jan 09, 2025 at 10:38:27PM +0500, Muhammad Usama Anjum wrote: > Remove the following warnings by removing unused argc and argv > parameters: > In function ‘main’: > warning: unused parameter ‘argc’ [-Wunused-parameter] > 158 | int main(int argc, char *argv[]) > | ~~~~^~~~ > warning: unused parameter ‘argv’ [-Wunused-parameter] > 158 | int main(int argc, char *argv[]) > | ~~~~~~^~~~~~ > > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> > --- > tools/testing/selftests/mm/compaction_test.c | 2 +- > tools/testing/selftests/mm/cow.c | 2 +- > tools/testing/selftests/mm/droppable.c | 2 +- > tools/testing/selftests/mm/gup_longterm.c | 2 +- > tools/testing/selftests/mm/hugepage-vmemmap.c | 2 +- > tools/testing/selftests/mm/hugetlb-madvise.c | 2 +- > tools/testing/selftests/mm/hugetlb-soft-offline.c | 2 +- > tools/testing/selftests/mm/madv_populate.c | 2 +- > tools/testing/selftests/mm/map_populate.c | 2 +- > tools/testing/selftests/mm/memfd_secret.c | 2 +- > tools/testing/selftests/mm/mlock-random-test.c | 2 +- > tools/testing/selftests/mm/mlock2-tests.c | 2 +- > tools/testing/selftests/mm/on-fault-limit.c | 2 +- > tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +- > tools/testing/selftests/mm/soft-dirty.c | 2 +- > tools/testing/selftests/mm/uffd-wp-mremap.c | 2 +- > tools/testing/selftests/mm/virtual_address_range.c | 2 +- > 17 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c > index 2c3a0eb6b22d3..8d23b698ce9db 100644 > --- a/tools/testing/selftests/mm/compaction_test.c > +++ b/tools/testing/selftests/mm/compaction_test.c > @@ -194,7 +194,7 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages) > return ret; > } > > -int main(int argc, char **argv) > +int main(void) > { > struct rlimit lim; > struct map_list *list = NULL, *entry; > diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c > index 1238e1c5aae15..ea00c85c76caa 100644 > --- a/tools/testing/selftests/mm/cow.c > +++ b/tools/testing/selftests/mm/cow.c > @@ -1769,7 +1769,7 @@ static int tests_per_non_anon_test_case(void) > return tests; > } > > -int main(int argc, char **argv) > +int main(void) > { > int err; > struct thp_settings default_settings; > diff --git a/tools/testing/selftests/mm/droppable.c b/tools/testing/selftests/mm/droppable.c > index f3d9ecf96890a..90ea6377810c5 100644 > --- a/tools/testing/selftests/mm/droppable.c > +++ b/tools/testing/selftests/mm/droppable.c > @@ -15,7 +15,7 @@ > > #include "../kselftest.h" > > -int main(int argc, char *argv[]) > +int main(void) > { > size_t alloc_size = 134217728; > size_t page_size = getpagesize(); > diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c > index 9423ad439a614..03a31dcb57577 100644 > --- a/tools/testing/selftests/mm/gup_longterm.c > +++ b/tools/testing/selftests/mm/gup_longterm.c > @@ -444,7 +444,7 @@ static int tests_per_test_case(void) > return 3 + nr_hugetlbsizes; > } > > -int main(int argc, char **argv) > +int main(void) > { > int i, err; > > diff --git a/tools/testing/selftests/mm/hugepage-vmemmap.c b/tools/testing/selftests/mm/hugepage-vmemmap.c > index df366a4d1b92d..23e97e552057d 100644 > --- a/tools/testing/selftests/mm/hugepage-vmemmap.c > +++ b/tools/testing/selftests/mm/hugepage-vmemmap.c > @@ -87,7 +87,7 @@ static int check_page_flags(unsigned long pfn) > return 0; > } > > -int main(int argc, char **argv) > +int main(void) > { > void *addr; > unsigned long pfn; > diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c > index e74107185324f..43f16c12c8e9a 100644 > --- a/tools/testing/selftests/mm/hugetlb-madvise.c > +++ b/tools/testing/selftests/mm/hugetlb-madvise.c > @@ -58,7 +58,7 @@ void read_fault_pages(void *addr, unsigned long nr_pages) > } > } > > -int main(int argc, char **argv) > +int main(int __attribute__((unused)) argc, char **argv) Can we add a macro in kselftest.h for "__unused" like the kernel already does? Then instead of removing args, we can just mark them, like you're doing here.
On 1/9/25 10:42 PM, Kees Cook wrote: > On Thu, Jan 09, 2025 at 10:38:27PM +0500, Muhammad Usama Anjum wrote: >> Remove the following warnings by removing unused argc and argv >> parameters: >> In function ‘main’: >> warning: unused parameter ‘argc’ [-Wunused-parameter] >> 158 | int main(int argc, char *argv[]) >> | ~~~~^~~~ >> warning: unused parameter ‘argv’ [-Wunused-parameter] >> 158 | int main(int argc, char *argv[]) >> | ~~~~~~^~~~~~ >> >> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> >> --- >> tools/testing/selftests/mm/compaction_test.c | 2 +- >> tools/testing/selftests/mm/cow.c | 2 +- >> tools/testing/selftests/mm/droppable.c | 2 +- >> tools/testing/selftests/mm/gup_longterm.c | 2 +- >> tools/testing/selftests/mm/hugepage-vmemmap.c | 2 +- >> tools/testing/selftests/mm/hugetlb-madvise.c | 2 +- >> tools/testing/selftests/mm/hugetlb-soft-offline.c | 2 +- >> tools/testing/selftests/mm/madv_populate.c | 2 +- >> tools/testing/selftests/mm/map_populate.c | 2 +- >> tools/testing/selftests/mm/memfd_secret.c | 2 +- >> tools/testing/selftests/mm/mlock-random-test.c | 2 +- >> tools/testing/selftests/mm/mlock2-tests.c | 2 +- >> tools/testing/selftests/mm/on-fault-limit.c | 2 +- >> tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +- >> tools/testing/selftests/mm/soft-dirty.c | 2 +- >> tools/testing/selftests/mm/uffd-wp-mremap.c | 2 +- >> tools/testing/selftests/mm/virtual_address_range.c | 2 +- >> 17 files changed, 17 insertions(+), 17 deletions(-) >> >> diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c >> index 2c3a0eb6b22d3..8d23b698ce9db 100644 >> --- a/tools/testing/selftests/mm/compaction_test.c >> +++ b/tools/testing/selftests/mm/compaction_test.c >> @@ -194,7 +194,7 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages) >> return ret; >> } >> >> -int main(int argc, char **argv) >> +int main(void) >> { >> struct rlimit lim; >> struct map_list *list = NULL, *entry; >> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c >> index 1238e1c5aae15..ea00c85c76caa 100644 >> --- a/tools/testing/selftests/mm/cow.c >> +++ b/tools/testing/selftests/mm/cow.c >> @@ -1769,7 +1769,7 @@ static int tests_per_non_anon_test_case(void) >> return tests; >> } >> >> -int main(int argc, char **argv) >> +int main(void) >> { >> int err; >> struct thp_settings default_settings; >> diff --git a/tools/testing/selftests/mm/droppable.c b/tools/testing/selftests/mm/droppable.c >> index f3d9ecf96890a..90ea6377810c5 100644 >> --- a/tools/testing/selftests/mm/droppable.c >> +++ b/tools/testing/selftests/mm/droppable.c >> @@ -15,7 +15,7 @@ >> >> #include "../kselftest.h" >> >> -int main(int argc, char *argv[]) >> +int main(void) >> { >> size_t alloc_size = 134217728; >> size_t page_size = getpagesize(); >> diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c >> index 9423ad439a614..03a31dcb57577 100644 >> --- a/tools/testing/selftests/mm/gup_longterm.c >> +++ b/tools/testing/selftests/mm/gup_longterm.c >> @@ -444,7 +444,7 @@ static int tests_per_test_case(void) >> return 3 + nr_hugetlbsizes; >> } >> >> -int main(int argc, char **argv) >> +int main(void) >> { >> int i, err; >> >> diff --git a/tools/testing/selftests/mm/hugepage-vmemmap.c b/tools/testing/selftests/mm/hugepage-vmemmap.c >> index df366a4d1b92d..23e97e552057d 100644 >> --- a/tools/testing/selftests/mm/hugepage-vmemmap.c >> +++ b/tools/testing/selftests/mm/hugepage-vmemmap.c >> @@ -87,7 +87,7 @@ static int check_page_flags(unsigned long pfn) >> return 0; >> } >> >> -int main(int argc, char **argv) >> +int main(void) >> { >> void *addr; >> unsigned long pfn; >> diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c >> index e74107185324f..43f16c12c8e9a 100644 >> --- a/tools/testing/selftests/mm/hugetlb-madvise.c >> +++ b/tools/testing/selftests/mm/hugetlb-madvise.c >> @@ -58,7 +58,7 @@ void read_fault_pages(void *addr, unsigned long nr_pages) >> } >> } >> >> -int main(int argc, char **argv) >> +int main(int __attribute__((unused)) argc, char **argv) > > Can we add a macro in kselftest.h for "__unused" like the kernel already > does? It can be done. But as there kselftest patches aren't regulated as much as other kernel patches, people may still not use this macro and use the gcc attribute directly. Let's see what others have to say. > Then instead of removing args, we can just mark them, like you're > doing here. In this case, argv is being used while argc isn't being used. I didn't find a way to keep argv and remove argc. Hence I marked argc as unused. For the all other case, why should we keep argv/argc and mark them unused as well when they aren't being used?
On Thu, Jan 09, 2025 at 10:48:52PM +0500, Muhammad Usama Anjum wrote: > For the all other case, why should we keep argv/argc and mark them unused > as well when they aren't being used? I'm fine either way, but my personal code style instinct is to keep the "standard" main declaration with argc/argv present. But it's mostly aesthetic. And if you think use of kselftest.h isn't universal, then perhaps we can avoid the macro, but it does seem nicer and more "normal" feeling for the rest of kernel development. -Kees
On Thu, 9 Jan 2025 09:50:45 -0800 Kees Cook <kees@kernel.org> wrote: > On Thu, Jan 09, 2025 at 10:48:52PM +0500, Muhammad Usama Anjum wrote: > > For the all other case, why should we keep argv/argc and mark them unused > > as well when they aren't being used? > > I'm fine either way, but my personal code style instinct is to keep the > "standard" main declaration with argc/argv present. But it's mostly > aesthetic. > > And if you think use of kselftest.h isn't universal, then perhaps we can > avoid the macro, but it does seem nicer and more "normal" feeling for > the rest of kernel development. > Agreed. __attribute__((unused)) is a bit of a mouthful and isn't what the kernel developer's eye expects to see.
diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c index 2c3a0eb6b22d3..8d23b698ce9db 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -194,7 +194,7 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages) return ret; } -int main(int argc, char **argv) +int main(void) { struct rlimit lim; struct map_list *list = NULL, *entry; diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 1238e1c5aae15..ea00c85c76caa 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -1769,7 +1769,7 @@ static int tests_per_non_anon_test_case(void) return tests; } -int main(int argc, char **argv) +int main(void) { int err; struct thp_settings default_settings; diff --git a/tools/testing/selftests/mm/droppable.c b/tools/testing/selftests/mm/droppable.c index f3d9ecf96890a..90ea6377810c5 100644 --- a/tools/testing/selftests/mm/droppable.c +++ b/tools/testing/selftests/mm/droppable.c @@ -15,7 +15,7 @@ #include "../kselftest.h" -int main(int argc, char *argv[]) +int main(void) { size_t alloc_size = 134217728; size_t page_size = getpagesize(); diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c index 9423ad439a614..03a31dcb57577 100644 --- a/tools/testing/selftests/mm/gup_longterm.c +++ b/tools/testing/selftests/mm/gup_longterm.c @@ -444,7 +444,7 @@ static int tests_per_test_case(void) return 3 + nr_hugetlbsizes; } -int main(int argc, char **argv) +int main(void) { int i, err; diff --git a/tools/testing/selftests/mm/hugepage-vmemmap.c b/tools/testing/selftests/mm/hugepage-vmemmap.c index df366a4d1b92d..23e97e552057d 100644 --- a/tools/testing/selftests/mm/hugepage-vmemmap.c +++ b/tools/testing/selftests/mm/hugepage-vmemmap.c @@ -87,7 +87,7 @@ static int check_page_flags(unsigned long pfn) return 0; } -int main(int argc, char **argv) +int main(void) { void *addr; unsigned long pfn; diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c index e74107185324f..43f16c12c8e9a 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -58,7 +58,7 @@ void read_fault_pages(void *addr, unsigned long nr_pages) } } -int main(int argc, char **argv) +int main(int __attribute__((unused)) argc, char **argv) { unsigned long free_hugepages; void *addr, *addr2; diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c index f086f0e04756f..cb087303f5ed3 100644 --- a/tools/testing/selftests/mm/hugetlb-soft-offline.c +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c @@ -216,7 +216,7 @@ static void test_soft_offline_common(int enable_soft_offline) enable_soft_offline); } -int main(int argc, char **argv) +int main(void) { ksft_print_header(); ksft_set_plan(2); diff --git a/tools/testing/selftests/mm/madv_populate.c b/tools/testing/selftests/mm/madv_populate.c index ef7d911da13e0..c6a3ee56a54a9 100644 --- a/tools/testing/selftests/mm/madv_populate.c +++ b/tools/testing/selftests/mm/madv_populate.c @@ -281,7 +281,7 @@ static int system_has_softdirty(void) #endif } -int main(int argc, char **argv) +int main(void) { int nr_tests = 16; int err; diff --git a/tools/testing/selftests/mm/map_populate.c b/tools/testing/selftests/mm/map_populate.c index 5c8a53869b1bd..0dd849b4affa6 100644 --- a/tools/testing/selftests/mm/map_populate.c +++ b/tools/testing/selftests/mm/map_populate.c @@ -74,7 +74,7 @@ static int child_f(int sock, unsigned long *smap, int fd) return ksft_cnt.ksft_pass; } -int main(int argc, char **argv) +int main(void) { int sock[2], child, ret; FILE *ftmp; diff --git a/tools/testing/selftests/mm/memfd_secret.c b/tools/testing/selftests/mm/memfd_secret.c index 74c911aa3aea9..b9659fa357371 100644 --- a/tools/testing/selftests/mm/memfd_secret.c +++ b/tools/testing/selftests/mm/memfd_secret.c @@ -297,7 +297,7 @@ static void prepare(void) #define NUM_TESTS 6 -int main(int argc, char *argv[]) +int main(void) { int fd; diff --git a/tools/testing/selftests/mm/mlock-random-test.c b/tools/testing/selftests/mm/mlock-random-test.c index 1cd80b0f76c33..0d95d630d0450 100644 --- a/tools/testing/selftests/mm/mlock-random-test.c +++ b/tools/testing/selftests/mm/mlock-random-test.c @@ -236,7 +236,7 @@ static void test_mlock_outof_limit(char *p, int alloc_size) ksft_test_result_pass("%s\n", __func__); } -int main(int argc, char **argv) +int main(void) { char *p = NULL; diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c index 7f0d50fa361dc..358711e8191f7 100644 --- a/tools/testing/selftests/mm/mlock2-tests.c +++ b/tools/testing/selftests/mm/mlock2-tests.c @@ -425,7 +425,7 @@ static void test_mlockall(void) munlockall(); } -int main(int argc, char **argv) +int main(void) { int ret, size = 3 * getpagesize(); void *map; diff --git a/tools/testing/selftests/mm/on-fault-limit.c b/tools/testing/selftests/mm/on-fault-limit.c index 431c1277d83a1..ade160966c926 100644 --- a/tools/testing/selftests/mm/on-fault-limit.c +++ b/tools/testing/selftests/mm/on-fault-limit.c @@ -28,7 +28,7 @@ static void test_limit(void) munlockall(); } -int main(int argc, char **argv) +int main(void) { ksft_print_header(); ksft_set_plan(1); diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/testing/selftests/mm/pkey_sighandler_tests.c index 1ac8c88098807..249989f8b7a2a 100644 --- a/tools/testing/selftests/mm/pkey_sighandler_tests.c +++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c @@ -528,7 +528,7 @@ static void (*pkey_tests[])(void) = { test_pkru_sigreturn }; -int main(int argc, char *argv[]) +int main(void) { int i; diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c index 8e1462ce05326..7286c90fff1a3 100644 --- a/tools/testing/selftests/mm/soft-dirty.c +++ b/tools/testing/selftests/mm/soft-dirty.c @@ -187,7 +187,7 @@ static void test_mprotect_file(int pagemap_fd, int pagesize) test_mprotect(pagemap_fd, pagesize, false); } -int main(int argc, char **argv) +int main(void) { int pagemap_fd; int pagesize; diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c index 2c4f984bd73ca..f548b1e1f197c 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -331,7 +331,7 @@ static const struct testcase testcases[] = { }, }; -int main(int argc, char **argv) +int main(void) { struct thp_settings settings; int i, j, plan = 0; diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 4042fd878acd7..7993583450766 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -158,7 +158,7 @@ static int validate_complete_va_space(void) return 0; } -int main(int argc, char *argv[]) +int main(void) { char *ptr[NR_CHUNKS_LOW]; char **hptr;
Remove the following warnings by removing unused argc and argv parameters: In function ‘main’: warning: unused parameter ‘argc’ [-Wunused-parameter] 158 | int main(int argc, char *argv[]) | ~~~~^~~~ warning: unused parameter ‘argv’ [-Wunused-parameter] 158 | int main(int argc, char *argv[]) | ~~~~~~^~~~~~ Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> --- tools/testing/selftests/mm/compaction_test.c | 2 +- tools/testing/selftests/mm/cow.c | 2 +- tools/testing/selftests/mm/droppable.c | 2 +- tools/testing/selftests/mm/gup_longterm.c | 2 +- tools/testing/selftests/mm/hugepage-vmemmap.c | 2 +- tools/testing/selftests/mm/hugetlb-madvise.c | 2 +- tools/testing/selftests/mm/hugetlb-soft-offline.c | 2 +- tools/testing/selftests/mm/madv_populate.c | 2 +- tools/testing/selftests/mm/map_populate.c | 2 +- tools/testing/selftests/mm/memfd_secret.c | 2 +- tools/testing/selftests/mm/mlock-random-test.c | 2 +- tools/testing/selftests/mm/mlock2-tests.c | 2 +- tools/testing/selftests/mm/on-fault-limit.c | 2 +- tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +- tools/testing/selftests/mm/soft-dirty.c | 2 +- tools/testing/selftests/mm/uffd-wp-mremap.c | 2 +- tools/testing/selftests/mm/virtual_address_range.c | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-)