Skip to contentSkip to conversation

save_restore: remove the duplicate 'const' declaration

LTP Li Wang 3 participants 8 messages Mar 10, 2022 – Mar 11, 2022 Library code

lore
Share & tools
lore

Li Wang

author
#0 lore raw
---
 include/tst_test.h                                        | 2 +-
 lib/newlib_tests/test19.c                                 | 2 +-
 lib/newlib_tests/test20.c                                 | 2 +-
 lib/tst_test.c                                            | 2 +-
 testcases/cve/icmp_rate_limit01.c                         | 2 +-
 testcases/kernel/containers/userns/userns08.c             | 2 +-
 testcases/kernel/mem/ksm/ksm01.c                          | 2 +-
 testcases/kernel/mem/ksm/ksm02.c                          | 2 +-
 testcases/kernel/mem/ksm/ksm03.c                          | 2 +-
 testcases/kernel/mem/ksm/ksm04.c                          | 2 +-
 testcases/kernel/mem/ksm/ksm05.c                          | 2 +-
 testcases/kernel/mem/ksm/ksm06.c                          | 2 +-
 testcases/kernel/syscalls/add_key/add_key05.c             | 2 +-
 testcases/kernel/syscalls/bind/bind06.c                   | 2 +-
 testcases/kernel/syscalls/madvise/madvise08.c             | 2 +-
 testcases/kernel/syscalls/migrate_pages/migrate_pages02.c | 2 +-
 testcases/kernel/syscalls/sendto/sendto03.c               | 2 +-
 testcases/kernel/syscalls/setsockopt/setsockopt05.c       | 2 +-
 testcases/kernel/syscalls/setsockopt/setsockopt06.c       | 2 +-
 testcases/kernel/syscalls/setsockopt/setsockopt07.c       | 2 +-
 testcases/kernel/syscalls/setsockopt/setsockopt08.c       | 2 +-
 testcases/kernel/syscalls/setsockopt/setsockopt09.c       | 2 +-
 22 files changed, 22 insertions(+), 22 deletions(-)
include/tst_test.h +1 -1
index e514efa76..3bedcc707 100644
@@ -259,7 +259,7 @@ struct tst_test {
 	 * NULL terminated array of (/proc, /sys) files to save
 	 * before setup and restore after cleanup
 	 */
-	const struct tst_path_val const *save_restore;
+	const struct tst_path_val *save_restore;
 
 	/*
 	 * NULL terminated array of kernel config options required for the
lib/newlib_tests/test19.c +1 -1
index 402a2ad30..4359a58ea 100644
@@ -23,7 +23,7 @@ static struct tst_test test = {
 	.needs_root = 1,
 	.test_all = run,
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/nonexistent", NULL},
 		{"!/proc/sys/kernel/numa_balancing", NULL},
 		{"/proc/sys/kernel/core_pattern", NULL},
lib/newlib_tests/test20.c +1 -1
index 5feb7c144..aaa424c83 100644
@@ -36,7 +36,7 @@ static void do_test(void) {
 static struct tst_test test = {
 	.test_all = do_test,
 	.request_hugepages = 2,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"!/proc/sys/kernel/numa_balancing", "0"},
 		NULL,
 	},
lib/tst_test.c +1 -1
index fe2e2bb6c..384c73e16 100644
@@ -1105,7 +1105,7 @@ static void do_setup(int argc, char *argv[])
 		tst_tmpdir();
 
 	if (tst_test->save_restore) {
-		const struct tst_path_val const *pvl = tst_test->save_restore;
+		const struct tst_path_val *pvl = tst_test->save_restore;
 
 		while (pvl->path) {
 			if (!tst_sys_conf_save(pvl->path))
testcases/cve/icmp_rate_limit01.c +1 -1
index 81735ce18..b8f159514 100644
@@ -268,7 +268,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/containers/userns/userns08.c +1 -1
index 33d0a9997..822b5c93f 100644
@@ -134,7 +134,7 @@ static struct tst_test test = {
 		"CONFIG_USER_NS",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/mem/ksm/ksm01.c +1 -1
index 305bf30ea..4265f7486 100644
@@ -79,7 +79,7 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"!/sys/kernel/mm/ksm/run", NULL},
 		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
testcases/kernel/mem/ksm/ksm02.c +1 -1
index 6ad7bcadb..daa8eb076 100644
@@ -97,7 +97,7 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"!/sys/kernel/mm/ksm/run", NULL},
 		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
testcases/kernel/mem/ksm/ksm03.c +1 -1
index 94223e332..f0115eb18 100644
@@ -82,7 +82,7 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"!/sys/kernel/mm/ksm/run", NULL},
 		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
testcases/kernel/mem/ksm/ksm04.c +1 -1
index 3e8a77bec..ec058aa01 100644
@@ -99,7 +99,7 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"!/sys/kernel/mm/ksm/run", NULL},
 		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
testcases/kernel/mem/ksm/ksm05.c +1 -1
index 33721d388..0c1ced5d7 100644
@@ -88,7 +88,7 @@ static struct tst_test test = {
 	.forks_child = 1,
 	.test_all = test_ksm,
 	.min_kver = "2.6.32",
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"!/sys/kernel/mm/ksm/run", "1"},
 		NULL,
 	},
testcases/kernel/mem/ksm/ksm06.c +1 -1
index f28383cc0..4f39be0b2 100644
@@ -136,7 +136,7 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
 		{"!/sys/kernel/mm/ksm/run", NULL},
 		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
testcases/kernel/syscalls/add_key/add_key05.c +1 -1
index bbe44e043..7a9cc6453 100644
@@ -214,7 +214,7 @@ static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
 	.cleanup = cleanup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/kernel/keys/gc_delay", "1"},
 		{"?/proc/sys/kernel/keys/maxkeys", "200"},
 		{"?/proc/sys/kernel/keys/maxbytes", "20000"},
testcases/kernel/syscalls/bind/bind06.c +1 -1
index 7a84b19cd..d0157d426 100644
@@ -109,7 +109,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
index e513d558a..b774bcd1c 100644
@@ -213,7 +213,7 @@ static struct tst_test test = {
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.forks_child = 1,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{CORE_PATTERN, NULL},
 		NULL,
 	},
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c +1 -1
index 162ff09a9..7552464b8 100644
@@ -326,7 +326,7 @@ static struct tst_test test = {
 	.forks_child = 1,
 	.test_all = run,
 	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/kernel/numa_balancing", "0"},
 		NULL,
 	},
testcases/kernel/syscalls/sendto/sendto03.c +1 -1
index 4459f8849..aa4dc3040 100644
@@ -217,7 +217,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/syscalls/setsockopt/setsockopt05.c +1 -1
index abc76627a..d7855cfab 100644
@@ -101,7 +101,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/syscalls/setsockopt/setsockopt06.c +1 -1
index 25dd04a15..e4c2671c0 100644
@@ -129,7 +129,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/syscalls/setsockopt/setsockopt07.c +1 -1
index b405c8ece..49c8fb6b4 100644
@@ -141,7 +141,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/syscalls/setsockopt/setsockopt08.c +1 -1
index 49eb17b13..864958b3e 100644
@@ -158,7 +158,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
testcases/kernel/syscalls/setsockopt/setsockopt09.c +1 -1
index 53944247f..4f03975ca 100644
@@ -105,7 +105,7 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
 		{"?/proc/sys/user/max_user_namespaces", NULL},
 		NULL,
 	},
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Li

lib/newlib_tests/test19.c static struct tst_test test = { · line 29

Quoted 11 lines
lib/newlib_tests/test19.c +1 -1
@@ -23,7 +23,7 @@ static struct tst_test test = {
  	.needs_root = 1,
  	.test_all = run,
  	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
  		{"?/proc/nonexistent", NULL},
  		{"!/proc/sys/kernel/numa_balancing", NULL},
  		{"/proc/sys/kernel/core_pattern", NULL},

Since tst_path_val is a struct array, we should use {NULL, NULL} or {} terminated instead of NULL terminated , otherwise it will report missing braces warning.

Best Regards
Yang Xu

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw
Quoted 17 lines · On Thu, Mar 10, 2022 at 4:38 PM [email protected] <…

Hi Li

lib/newlib_tests/test19.c static struct tst_test test = { · line 29

Quoted 11 lines
lib/newlib_tests/test19.c +1 -1
@@ -23,7 +23,7 @@ static struct tst_test test = {
      .needs_root = 1,
      .test_all = run,
      .setup = setup,
-     .save_restore = (const struct tst_path_val const[]) {
+     .save_restore = (const struct tst_path_val[]) {
              {"?/proc/nonexistent", NULL},
              {"!/proc/sys/kernel/numa_balancing", NULL},
              {"/proc/sys/kernel/core_pattern", NULL},

Since tst_path_val is a struct array, we should use {NULL, NULL} or {} terminated instead of NULL terminated , otherwise it will report missing braces warning.

Ah, right. Sorry!!!

Seems I was in so hurry to fix the const issue but overlook this.

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Li

Quoted 24 lines

On Thu, Mar 10, 2022 at 4:38 PM [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>> wrote:

    Hi Li
     > --- a/lib/newlib_tests/test19.c
     > +++ b/lib/newlib_tests/test19.c
     > @@ -23,7 +23,7 @@ static struct tst_test test = {
     > .needs_root = 1,
     > .test_all = run,
     > .setup = setup,
     > - .save_restore = (const struct tst_path_val const[]) {
     > + .save_restore = (const struct tst_path_val[]) {
     > {"?/proc/nonexistent", NULL},
     > {"!/proc/sys/kernel/numa_balancing", NULL},
     > {"/proc/sys/kernel/core_pattern", NULL},

    Since tst_path_val is a struct array, we should use {NULL, NULL} or {}
    terminated instead of NULL terminated , otherwise it will report
    missing
    braces warning.
Quoted 1 line

Ah, right. Sorry!!!

Never mind.

Quoted 2 lines

Seems I was in so hurry to fix the const issue but overlook this.

I also think you can add a separate patch to fix this comment in doc or in tst_test.h for other struct pointers.

         /*
          * NULL-terminated array to be allocated buffers.
          */
         struct tst_buffers *bufs;

         /*
          * NULL-terminated array of capability settings
          */
         struct tst_cap *caps;

Best Regards
Yang Xu

Quoted 4 lines

--
Regards,
Li Wang

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw
Quoted 26 lines · On Thu, Mar 10, 2022 at 4:53 PM [email protected] <…

Hi Li

Quoted 6 lines

On Thu, Mar 10, 2022 at 4:38 PM [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>> wrote:

Quoted 14 lines
    Hi Li
     > --- a/lib/newlib_tests/test19.c
     > +++ b/lib/newlib_tests/test19.c
     > @@ -23,7 +23,7 @@ static struct tst_test test = {
     > .needs_root = 1,
     > .test_all = run,
     > .setup = setup,
     > - .save_restore = (const struct tst_path_val const[]) {
     > + .save_restore = (const struct tst_path_val[]) {
     > {"?/proc/nonexistent", NULL},
     > {"!/proc/sys/kernel/numa_balancing", NULL},
     > {"/proc/sys/kernel/core_pattern", NULL},

    Since tst_path_val is a struct array, we should use {NULL, NULL} or

{}

Quoted 4 lines

terminated instead of NULL terminated , otherwise it will report missing
braces warning.

Quoted 7 lines
Quoted 1 line

Ah, right. Sorry!!!

Never mind.

Quoted 2 lines

Seems I was in so hurry to fix the const issue but overlook this.

I also think you can add a separate patch to fix this comment in doc or in tst_test.h for other struct pointers.

You are right. I will go through the whole part to see if other places need updates.

Thanks for finding this :).

Quoted 18 lines
         /*
          * NULL-terminated array to be allocated buffers.
          */
         struct tst_buffers *bufs;

         /*
          * NULL-terminated array of capability settings
          */
         struct tst_cap *caps;

Best Regards
Yang Xu

Quoted 4 lines

--
Regards,
Li Wang

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to [email protected]

Hi Richard

Quoted 16 lines

Hi Li

lib/newlib_tests/test19.c static struct tst_test test = { · line 29

Quoted 11 lines
lib/newlib_tests/test19.c +1 -1
@@ -23,7 +23,7 @@ static struct tst_test test = {
   	.needs_root = 1,
   	.test_all = run,
   	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
   		{"?/proc/nonexistent", NULL},
   		{"!/proc/sys/kernel/numa_balancing", NULL},
   		{"/proc/sys/kernel/core_pattern", NULL},

Since tst_path_val is a struct array, we should use {NULL, NULL} or {} terminated instead of NULL terminated , otherwise it will report missing braces warning.

Since we have the following rule
LTP-005 Array must terminate with a sentinel value (i.e. NULL or '{}')

Can we check struct array whether use {} terminated instead of NULL?

Best Regards
Yang Xu

Quoted 4 lines

Best Regards
Yang Xu

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hello,

Quoted 17 lines · "[email protected]" <[email protected]> writes:

Hi Richard

Quoted 16 lines

Hi Li

lib/newlib_tests/test19.c static struct tst_test test = { · line 29

Quoted 11 lines
lib/newlib_tests/test19.c +1 -1
@@ -23,7 +23,7 @@ static struct tst_test test = {
   	.needs_root = 1,
   	.test_all = run,
   	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
   		{"?/proc/nonexistent", NULL},
   		{"!/proc/sys/kernel/numa_balancing", NULL},
   		{"/proc/sys/kernel/core_pattern", NULL},

Since tst_path_val is a struct array, we should use {NULL, NULL} or {} terminated instead of NULL terminated , otherwise it will report missing braces warning.

Quoted 4 lines

Since we have the following rule
LTP-005 Array must terminate with a sentinel value (i.e. NULL or '{}')

Can we check struct array whether use {} terminated instead of NULL?

I think so, however naively enabling the check causes a segfault in ptr_list_empty. Probably because there is no list, it's just NULL.

It already reports the missing braces, but I suppose this is not very helpful.

Quoted 7 lines

Best Regards
Yang Xu

Quoted 4 lines

Best Regards
Yang Xu

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi Richard

Quoted 24 lines

Hello,

Quoted 20 lines · "[email protected]"<[email protected]> writes:

Hi Richard

Quoted 16 lines

Hi Li

lib/newlib_tests/test19.c static struct tst_test test = { · line 29

Quoted 11 lines
lib/newlib_tests/test19.c +1 -1
@@ -23,7 +23,7 @@ static struct tst_test test = {
    	.needs_root = 1,
    	.test_all = run,
    	.setup = setup,
-	.save_restore = (const struct tst_path_val const[]) {
+	.save_restore = (const struct tst_path_val[]) {
    		{"?/proc/nonexistent", NULL},
    		{"!/proc/sys/kernel/numa_balancing", NULL},
    		{"/proc/sys/kernel/core_pattern", NULL},

Since tst_path_val is a struct array, we should use {NULL, NULL} or {} terminated instead of NULL terminated , otherwise it will report missing braces warning.

Since we have the following rule
LTP-005 Array must terminate with a sentinel value (i.e. NULL or '{}')

Quoted 7 lines
Quoted 1 line

Can we check struct array whether use {} terminated instead of NULL?

I think so, however naively enabling the check causes a segfault in ptr_list_empty. Probably because there is no list, it's just NULL.

It already reports the missing braces, but I suppose this is not very helpful.

Sound reasonable.

Best Regards
Yang Xu

Quoted 10 lines
Quoted 8 lines

Best Regards
Yang Xu

Quoted 4 lines

Best Regards
Yang Xu

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp