[07/14] sysctl: Add size arg to __register_sysctl_init

Message ID 20230726140635.2059334-8-j.granados@samsung.com
State New
Headers
Series [01/14] sysctl: Prefer ctl_table_header in proc_sysctl |

Commit Message

Joel Granados July 26, 2023, 2:06 p.m. UTC
  This is part of the effort to remove the sentinel element from the
ctl_table array at register time. We add a size argument to
__register_sysctl_init and modify the register_sysctl_init macro to
calculate the array size with ARRAY_SIZE. The original callers do not
need to be updated as they will go through the new macro.

Signed-off-by: Joel Granados <j.granados@samsung.com>
---
 fs/proc/proc_sysctl.c  | 11 ++---------
 include/linux/sysctl.h |  5 +++--
 2 files changed, 5 insertions(+), 11 deletions(-)
  

Comments

Simon Horman July 28, 2023, 10:56 a.m. UTC | #1
On Wed, Jul 26, 2023 at 04:06:27PM +0200, Joel Granados wrote:
> This is part of the effort to remove the sentinel element from the
> ctl_table array at register time. We add a size argument to
> __register_sysctl_init and modify the register_sysctl_init macro to
> calculate the array size with ARRAY_SIZE. The original callers do not
> need to be updated as they will go through the new macro.
> 
> Signed-off-by: Joel Granados <j.granados@samsung.com>
> ---
>  fs/proc/proc_sysctl.c  | 11 ++---------
>  include/linux/sysctl.h |  5 +++--
>  2 files changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index c04293911e7e..6c0721cd35f3 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -1444,16 +1444,9 @@ EXPORT_SYMBOL(register_sysctl_sz);
>   * Context: if your base directory does not exist it will be created for you.
>   */
>  void __init __register_sysctl_init(const char *path, struct ctl_table *table,
> -				 const char *table_name)
> +				 const char *table_name, size_t table_size)

Hi Joel,

in the same vein as my comment on another patch.
Please add table_size to the kernel doc for this function.
  
Joel Granados July 28, 2023, 4:11 p.m. UTC | #2
On Fri, Jul 28, 2023 at 12:56:36PM +0200, Simon Horman wrote:
> On Wed, Jul 26, 2023 at 04:06:27PM +0200, Joel Granados wrote:
> > This is part of the effort to remove the sentinel element from the
> > ctl_table array at register time. We add a size argument to
> > __register_sysctl_init and modify the register_sysctl_init macro to
> > calculate the array size with ARRAY_SIZE. The original callers do not
> > need to be updated as they will go through the new macro.
> > 
> > Signed-off-by: Joel Granados <j.granados@samsung.com>
> > ---
> >  fs/proc/proc_sysctl.c  | 11 ++---------
> >  include/linux/sysctl.h |  5 +++--
> >  2 files changed, 5 insertions(+), 11 deletions(-)
> > 
> > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> > index c04293911e7e..6c0721cd35f3 100644
> > --- a/fs/proc/proc_sysctl.c
> > +++ b/fs/proc/proc_sysctl.c
> > @@ -1444,16 +1444,9 @@ EXPORT_SYMBOL(register_sysctl_sz);
> >   * Context: if your base directory does not exist it will be created for you.
> >   */
> >  void __init __register_sysctl_init(const char *path, struct ctl_table *table,
> > -				 const char *table_name)
> > +				 const char *table_name, size_t table_size)
> 
> Hi Joel,
> 
> in the same vein as my comment on another patch.
> Please add table_size to the kernel doc for this function.
Will do.
  

Patch

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c04293911e7e..6c0721cd35f3 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -1444,16 +1444,9 @@  EXPORT_SYMBOL(register_sysctl_sz);
  * Context: if your base directory does not exist it will be created for you.
  */
 void __init __register_sysctl_init(const char *path, struct ctl_table *table,
-				 const char *table_name)
+				 const char *table_name, size_t table_size)
 {
-	int count = 0;
-	struct ctl_table *entry;
-	struct ctl_table_header t_hdr, *hdr;
-
-	t_hdr.ctl_table = table;
-	list_for_each_table_entry(entry, (&t_hdr))
-		count++;
-	hdr = register_sysctl_sz(path, table, count);
+	struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size);
 
 	if (unlikely(!hdr)) {
 		pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index b1168ae281c9..09d7429d67c0 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -236,8 +236,9 @@  void unregister_sysctl_table(struct ctl_table_header * table);
 
 extern int sysctl_init_bases(void);
 extern void __register_sysctl_init(const char *path, struct ctl_table *table,
-				 const char *table_name);
-#define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
+				 const char *table_name, size_t table_size);
+#define register_sysctl_init(path, table)	\
+	__register_sysctl_init(path, table, #table, ARRAY_SIZE(table))
 extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
 
 void do_sysctl_args(void);