mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c
@ 2022-09-08  8:29 Liu Shixin
  2022-09-08  8:29 ` [PATCH v2 1/2] kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c Liu Shixin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Liu Shixin @ 2022-09-08  8:29 UTC (permalink / raw)
  To: Luis Chamberlain, Kees Cook, Iurii Zaikin
  Cc: linux-kernel, linux-fsdevel, Liu Shixin

v1->v2: fix build error when !CONFIG_PROC_SYSCTL

Liu Shixin (2):
  kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c
  kernel/sysctl-test: use SYSCTL_{ZERO/ONE_HUNDRED} instead of
    i_{zero/one_hundred}

 fs/proc/proc_sysctl.c |  7 -------
 kernel/sysctl-test.c  | 43 ++++++++++++++++++++-----------------------
 kernel/sysctl.c       |  9 ++++++++-
 3 files changed, 28 insertions(+), 31 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c
  2022-09-08  8:29 [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Liu Shixin
@ 2022-09-08  8:29 ` Liu Shixin
  2022-09-08  8:29 ` [PATCH v2 2/2] kernel/sysctl-test: use SYSCTL_{ZERO/ONE_HUNDRED} instead of i_{zero/one_hundred} Liu Shixin
  2022-09-08 23:59 ` [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Luis Chamberlain
  2 siblings, 0 replies; 4+ messages in thread
From: Liu Shixin @ 2022-09-08  8:29 UTC (permalink / raw)
  To: Luis Chamberlain, Kees Cook, Iurii Zaikin
  Cc: linux-kernel, linux-fsdevel, Liu Shixin

sysctl_vals and sysctl_long_vals are declared even if sysctl is disabled.
Move its definition to sysctl.c to make sure their integrity in any case.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 fs/proc/proc_sysctl.c | 7 -------
 kernel/sysctl.c       | 9 ++++++++-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 021e83fe831f..42a7cdbe514b 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -28,13 +28,6 @@ static const struct inode_operations proc_sys_inode_operations;
 static const struct file_operations proc_sys_dir_file_operations;
 static const struct inode_operations proc_sys_dir_operations;
 
-/* shared constants to be used in various sysctls */
-const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
-EXPORT_SYMBOL(sysctl_vals);
-
-const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
-EXPORT_SYMBOL_GPL(sysctl_long_vals);
-
 /* Support for permanently empty directories */
 
 struct ctl_table sysctl_mount_point[] = {
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index f10a610aa834..8ccd8d755c5f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -82,9 +82,16 @@
 #include <linux/rtmutex.h>
 #endif
 
+/* shared constants to be used in various sysctls */
+const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
+EXPORT_SYMBOL(sysctl_vals);
+
+const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
+EXPORT_SYMBOL_GPL(sysctl_long_vals);
+
 #if defined(CONFIG_SYSCTL)
 
-/* Constants used for minimum and  maximum */
+/* Constants used for minimum and maximum */
 
 #ifdef CONFIG_PERF_EVENTS
 static const int six_hundred_forty_kb = 640 * 1024;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] kernel/sysctl-test: use SYSCTL_{ZERO/ONE_HUNDRED} instead of i_{zero/one_hundred}
  2022-09-08  8:29 [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Liu Shixin
  2022-09-08  8:29 ` [PATCH v2 1/2] kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c Liu Shixin
@ 2022-09-08  8:29 ` Liu Shixin
  2022-09-08 23:59 ` [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Luis Chamberlain
  2 siblings, 0 replies; 4+ messages in thread
From: Liu Shixin @ 2022-09-08  8:29 UTC (permalink / raw)
  To: Luis Chamberlain, Kees Cook, Iurii Zaikin
  Cc: linux-kernel, linux-fsdevel, Liu Shixin

It is better to use SYSCTL_ZERO and SYSCTL_ONE_HUNDRED instead of &i_zero
and &i_one_hundred, and then we can remove these two local variable.

No functional change.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 kernel/sysctl-test.c | 43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/kernel/sysctl-test.c b/kernel/sysctl-test.c
index 664ded05dd7a..6ef887c19c48 100644
--- a/kernel/sysctl-test.c
+++ b/kernel/sysctl-test.c
@@ -9,9 +9,6 @@
 #define KUNIT_PROC_READ 0
 #define KUNIT_PROC_WRITE 1
 
-static int i_zero;
-static int i_one_hundred = 100;
-
 /*
  * Test that proc_dointvec will not try to use a NULL .data field even when the
  * length is non-zero.
@@ -29,8 +26,8 @@ static void sysctl_test_api_dointvec_null_tbl_data(struct kunit *test)
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	/*
 	 * proc_dointvec expects a buffer in user space, so we allocate one. We
@@ -79,8 +76,8 @@ static void sysctl_test_api_dointvec_table_maxlen_unset(struct kunit *test)
 		.maxlen		= 0,
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	void __user *buffer = (void __user *)kunit_kzalloc(test, sizeof(int),
 							   GFP_USER);
@@ -122,8 +119,8 @@ static void sysctl_test_api_dointvec_table_len_is_zero(struct kunit *test)
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	void __user *buffer = (void __user *)kunit_kzalloc(test, sizeof(int),
 							   GFP_USER);
@@ -156,8 +153,8 @@ static void sysctl_test_api_dointvec_table_read_but_position_set(
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	void __user *buffer = (void __user *)kunit_kzalloc(test, sizeof(int),
 							   GFP_USER);
@@ -191,8 +188,8 @@ static void sysctl_test_dointvec_read_happy_single_positive(struct kunit *test)
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	size_t len = 4;
 	loff_t pos = 0;
@@ -222,8 +219,8 @@ static void sysctl_test_dointvec_read_happy_single_negative(struct kunit *test)
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	size_t len = 5;
 	loff_t pos = 0;
@@ -251,8 +248,8 @@ static void sysctl_test_dointvec_write_happy_single_positive(struct kunit *test)
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	char input[] = "9";
 	size_t len = sizeof(input) - 1;
@@ -281,8 +278,8 @@ static void sysctl_test_dointvec_write_happy_single_negative(struct kunit *test)
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	char input[] = "-9";
 	size_t len = sizeof(input) - 1;
@@ -313,8 +310,8 @@ static void sysctl_test_api_dointvec_write_single_less_int_min(
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	size_t max_len = 32, len = max_len;
 	loff_t pos = 0;
@@ -351,8 +348,8 @@ static void sysctl_test_api_dointvec_write_single_greater_int_max(
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
-		.extra1		= &i_zero,
-		.extra2         = &i_one_hundred,
+		.extra1		= SYSCTL_ZERO,
+		.extra2         = SYSCTL_ONE_HUNDRED,
 	};
 	size_t max_len = 32, len = max_len;
 	loff_t pos = 0;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c
  2022-09-08  8:29 [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Liu Shixin
  2022-09-08  8:29 ` [PATCH v2 1/2] kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c Liu Shixin
  2022-09-08  8:29 ` [PATCH v2 2/2] kernel/sysctl-test: use SYSCTL_{ZERO/ONE_HUNDRED} instead of i_{zero/one_hundred} Liu Shixin
@ 2022-09-08 23:59 ` Luis Chamberlain
  2 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2022-09-08 23:59 UTC (permalink / raw)
  To: Liu Shixin; +Cc: Kees Cook, Iurii Zaikin, linux-kernel, linux-fsdevel

On Thu, Sep 08, 2022 at 04:29:45PM +0800, Liu Shixin wrote:
> v1->v2: fix build error when !CONFIG_PROC_SYSCTL
> 
> Liu Shixin (2):
>   kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c
>   kernel/sysctl-test: use SYSCTL_{ZERO/ONE_HUNDRED} instead of
>     i_{zero/one_hundred}
> 
>  fs/proc/proc_sysctl.c |  7 -------
>  kernel/sysctl-test.c  | 43 ++++++++++++++++++++-----------------------
>  kernel/sysctl.c       |  9 ++++++++-
>  3 files changed, 28 insertions(+), 31 deletions(-)

Queued up on sysctl-testing thanks!

  Luis

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-08 23:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-08  8:29 [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Liu Shixin
2022-09-08  8:29 ` [PATCH v2 1/2] kernel/sysctl.c: move sysctl_vals and sysctl_long_vals to sysctl.c Liu Shixin
2022-09-08  8:29 ` [PATCH v2 2/2] kernel/sysctl-test: use SYSCTL_{ZERO/ONE_HUNDRED} instead of i_{zero/one_hundred} Liu Shixin
2022-09-08 23:59 ` [PATCH v2 0/2] Use sysctl_vals in sysctl-test.c Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®