[PATCH v2] fs/proc: Optimize arrays defined by struct ctl_path

David Laight David.Laight at ACULAB.COM
Thu Feb 24 11:05:35 UTC 2022


From: Meng Tang <tangmeng at uniontech.com>
> Sent: 24 February 2022 10:53
> 
> Previously, arrays defined by struct ctl_path is terminated
> with an empty one. For example, when we actually only register
> one ctl_path, we've gone from 8 bytes to 16 bytes.
> 
...
> diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c
> index 2df115d0e210..b9290a252d84 100644
> --- a/arch/csky/abiv1/alignment.c
> +++ b/arch/csky/abiv1/alignment.c
> @@ -340,14 +340,14 @@ static struct ctl_table sysctl_table[2] = {
>  	{}
>  };
> 
> -static struct ctl_path sysctl_path[2] = {
> -	{.procname = "csky"},
> -	{}
> +static struct ctl_path sysctl_path[1] = {
> +	{.procname = "csky"}
>  };
> +#define SYSCTL_PATH_NUM ARRAY_SIZE(sysctl_path)
> 
>  static int __init csky_alignment_init(void)
>  {
> -	 (sysctl_path, sysctl_table);
> +	register_sysctl_paths(sysctl_path, SYSCTL_PATH_NUM, sysctl_table);
>  	return 0;
>  }

That is horribly error prone.
What might work is to add the ctl_path_num parameter but leave in the
check for NULL.
Then add:

#define register_sysctl_paths(p, t) register_sysctl_paths(p, ARRAY_SIZE(t), t)

in the header file after the prototype.
Put the function name in () in the definition to stop the macro expansion.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)



More information about the Linux-security-module-archive mailing list