public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Phillip Potter <phil@philpotter•co.uk>
To: Luis Chamberlain <mcgrof@kernel•org>, axboe@kernel•dk
Cc: jack@suse•cz, airlied@linux•ie, amir73il@gmail•com,
	clemens@ladisch•de, dri-devel@lists•freedesktop.org,
	phil@philpotter•co.uk, joseph.qi@linux•alibaba.com,
	mark@fasheh•com, yzaikin@google•com,
	joonas.lahtinen@linux•intel.com, keescook@chromium•org,
	arnd@arndb•de, intel-gfx@lists•freedesktop.org,
	jani.nikula@linux•intel.com, linux-block@vger•kernel.org,
	viro@zeniv•linux.org.uk, rodrigo.vivi@intel•com,
	nixiaoming@huawei•com, tvrtko.ursulin@linux•intel.com,
	gregkh@linuxfoundation•org, linux-kernel@vger•kernel.org,
	julia.lawall@inria•fr, ebiederm@xmission•com,
	linux-fsdevel@vger•kernel.org, akpm@linux-foundation•org,
	linuxppc-dev@lists•ozlabs.org, ocfs2-devel@oss•oracle.com,
	jlbec@evilplan•org
Subject: Re: [PATCH v2 7/8] cdrom: simplify subdirectory registration with register_sysctl()
Date: Thu, 25 Nov 2021 09:23:03 +0000	[thread overview]
Message-ID: <YZ9V9yxGapfPF4+g@equinox> (raw)
In-Reply-To: <20211123202422.819032-8-mcgrof@kernel.org>

On Tue, Nov 23, 2021 at 12:24:21PM -0800, Luis Chamberlain wrote:
> There is no need to user boiler plate code to specify a set of base
> directories we're going to stuff sysctls under. Simplify this by using
> register_sysctl() and specifying the directory path directly.
> 
> // pycocci sysctl-subdir-register-sysctl-simplify.cocci PATH
> 
> @c1@
> expression E1;
> identifier subdir, sysctls;
> @@
> 
> static struct ctl_table subdir[] = {
> 	{
> 		.procname = E1,
> 		.maxlen = 0,
> 		.mode = 0555,
> 		.child = sysctls,
> 	},
> 	{ }
> };
> 
> @c2@
> identifier c1.subdir;
> 
> expression E2;
> identifier base;
> @@
> 
> static struct ctl_table base[] = {
> 	{
> 		.procname = E2,
> 		.maxlen = 0,
> 		.mode = 0555,
> 		.child = subdir,
> 	},
> 	{ }
> };
> 
> @c3@
> identifier c2.base;
> identifier header;
> @@
> 
> header = register_sysctl_table(base);
> 
> @r1 depends on c1 && c2 && c3@
> expression c1.E1;
> identifier c1.subdir, c1.sysctls;
> @@
> 
> -static struct ctl_table subdir[] = {
> -	{
> -		.procname = E1,
> -		.maxlen = 0,
> -		.mode = 0555,
> -		.child = sysctls,
> -	},
> -	{ }
> -};
> 
> @r2 depends on c1 && c2 && c3@
> identifier c1.subdir;
> 
> expression c2.E2;
> identifier c2.base;
> @@
> -static struct ctl_table base[] = {
> -	{
> -		.procname = E2,
> -		.maxlen = 0,
> -		.mode = 0555,
> -		.child = subdir,
> -	},
> -	{ }
> -};
> 
> @initialize:python@
> @@
> 
> def make_my_fresh_expression(s1, s2):
>   return '"' + s1.strip('"') + "/" + s2.strip('"') + '"'
> 
> @r3 depends on c1 && c2 && c3@
> expression c1.E1;
> identifier c1.sysctls;
> expression c2.E2;
> identifier c2.base;
> identifier c3.header;
> fresh identifier E3 = script:python(E2, E1) { make_my_fresh_expression(E2, E1) };
> @@
> 
> header =
> -register_sysctl_table(base);
> +register_sysctl(E3, sysctls);
> 
> Generated-by: Coccinelle SmPL
> Signed-off-by: Luis Chamberlain <mcgrof@kernel•org>
> ---
>  drivers/cdrom/cdrom.c | 23 +----------------------
>  1 file changed, 1 insertion(+), 22 deletions(-)
> 
> diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
> index 9877e413fce3..1b57d4666e43 100644
> --- a/drivers/cdrom/cdrom.c
> +++ b/drivers/cdrom/cdrom.c
> @@ -3691,27 +3691,6 @@ static struct ctl_table cdrom_table[] = {
>  	},
>  	{ }
>  };
> -
> -static struct ctl_table cdrom_cdrom_table[] = {
> -	{
> -		.procname	= "cdrom",
> -		.maxlen		= 0,
> -		.mode		= 0555,
> -		.child		= cdrom_table,
> -	},
> -	{ }
> -};
> -
> -/* Make sure that /proc/sys/dev is there */
> -static struct ctl_table cdrom_root_table[] = {
> -	{
> -		.procname	= "dev",
> -		.maxlen		= 0,
> -		.mode		= 0555,
> -		.child		= cdrom_cdrom_table,
> -	},
> -	{ }
> -};
>  static struct ctl_table_header *cdrom_sysctl_header;
>  
>  static void cdrom_sysctl_register(void)
> @@ -3721,7 +3700,7 @@ static void cdrom_sysctl_register(void)
>  	if (!atomic_add_unless(&initialized, 1, 1))
>  		return;
>  
> -	cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
> +	cdrom_sysctl_header = register_sysctl("dev/cdrom", cdrom_table);
>  
>  	/* set the defaults */
>  	cdrom_sysctl_settings.autoclose = autoclose;
> -- 
> 2.33.0
> 

Dear Luis,

Thank you for the patch. Tested and working, looks good to me. As this
has already been pulled into Andrew Morton's tree, I have added in Jens
and the linux-block list so there is awareness that the patch will go
via -mm then linux-next tree.

For what it's worth (although guess it won't be in the commit now):
Reviewed-by: Phillip Potter <phil@philpotter•co.uk>

Regards,
Phil

  reply	other threads:[~2021-11-25 11:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23 20:24 [PATCH v2 0/8] sysctl: second set of kernel/sysctl cleanups Luis Chamberlain
2021-11-23 20:24 ` [PATCH v2 1/8] hpet: simplify subdirectory registration with register_sysctl() Luis Chamberlain
2021-11-23 20:24 ` [PATCH v2 2/8] i915: " Luis Chamberlain
2021-11-25  9:41   ` Jani Nikula
2021-11-23 20:24 ` [PATCH v2 3/8] macintosh/mac_hid.c: " Luis Chamberlain
2021-11-23 20:24 ` [PATCH v2 4/8] ocfs2: " Luis Chamberlain
2021-11-24  9:49   ` Jan Kara
2021-11-23 20:24 ` [PATCH v2 5/8] test_sysctl: " Luis Chamberlain
2021-11-23 20:24 ` [PATCH v2 6/8] inotify: " Luis Chamberlain
2021-11-24  9:44   ` Jan Kara
2021-11-24 13:40     ` Luis Chamberlain
2021-11-23 20:24 ` [PATCH v2 7/8] cdrom: " Luis Chamberlain
2021-11-25  9:23   ` Phillip Potter [this message]
2021-11-23 20:24 ` [PATCH v2 8/8] eventpoll: simplify sysctl declaration " Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YZ9V9yxGapfPF4+g@equinox \
    --to=phil@philpotter$(echo .)co.uk \
    --cc=airlied@linux$(echo .)ie \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=amir73il@gmail$(echo .)com \
    --cc=arnd@arndb$(echo .)de \
    --cc=axboe@kernel$(echo .)dk \
    --cc=clemens@ladisch$(echo .)de \
    --cc=dri-devel@lists$(echo .)freedesktop.org \
    --cc=ebiederm@xmission$(echo .)com \
    --cc=gregkh@linuxfoundation$(echo .)org \
    --cc=intel-gfx@lists$(echo .)freedesktop.org \
    --cc=jack@suse$(echo .)cz \
    --cc=jani.nikula@linux$(echo .)intel.com \
    --cc=jlbec@evilplan$(echo .)org \
    --cc=joonas.lahtinen@linux$(echo .)intel.com \
    --cc=joseph.qi@linux$(echo .)alibaba.com \
    --cc=julia.lawall@inria$(echo .)fr \
    --cc=keescook@chromium$(echo .)org \
    --cc=linux-block@vger$(echo .)kernel.org \
    --cc=linux-fsdevel@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=mark@fasheh$(echo .)com \
    --cc=mcgrof@kernel$(echo .)org \
    --cc=nixiaoming@huawei$(echo .)com \
    --cc=ocfs2-devel@oss$(echo .)oracle.com \
    --cc=rodrigo.vivi@intel$(echo .)com \
    --cc=tvrtko.ursulin@linux$(echo .)intel.com \
    --cc=viro@zeniv$(echo .)linux.org.uk \
    --cc=yzaikin@google$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox