public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Junwen Wu <wudaemon@163.com>
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND v2] char: misc:use DEFINE_PROC_SHOW_ATTRIBUTE micro to simplify misc proc_fops
Date: Tue, 26 Apr 2022 12:51:09 +0200	[thread overview]
Message-ID: <YmfOncISX6vjQW2I@kroah.com> (raw)
In-Reply-To: <20220410151628.288568-1-wudaemon@163.com>

On Sun, Apr 10, 2022 at 03:16:27PM +0000, Junwen Wu wrote:
> From: wujunwen <wudaemon@163.com>
> 
> DEFINE_PROC_SHOW_ATTRIBUTE is used to simply seq_file flow ,so
> we can use it to simplify misc proc_fops.
> 
> Signed-off-by: wujunwen <wudaemon@163.com>
> ---
> V1 -> V2: Fix compile error with no "CONFIG_PROC_FS"
> 
>  drivers/char/misc.c | 41 ++++++++++++++---------------------------
>  1 file changed, 14 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index ca5141ed5ef3..076b7f08aa7a 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -64,40 +64,23 @@ static DEFINE_MUTEX(misc_mtx);
>  static DECLARE_BITMAP(misc_minors, DYNAMIC_MINORS);
>  
>  #ifdef CONFIG_PROC_FS
> -static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
> -{
> -	mutex_lock(&misc_mtx);
> -	return seq_list_start(&misc_list, *pos);
> -}
>  
> -static void *misc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> +static int misc_show(struct seq_file *seq, void *v)
>  {
> -	return seq_list_next(v, &misc_list, pos);
> -}
> +	const struct miscdevice *p;
>  
> -static void misc_seq_stop(struct seq_file *seq, void *v)
> -{
> +	mutex_lock(&misc_mtx);
> +	list_for_each_entry(p, &misc_list, list) {
> +		seq_printf(seq, "%3i %s\n", p->minor, p->name ? p->name : "");
> +	}
>  	mutex_unlock(&misc_mtx);
> -}
> -
> -static int misc_seq_show(struct seq_file *seq, void *v)
> -{
> -	const struct miscdevice *p = list_entry(v, struct miscdevice, list);
> -
> -	seq_printf(seq, "%3i %s\n", p->minor, p->name ? p->name : "");
>  	return 0;
>  }
>  
> -
> -static const struct seq_operations misc_seq_ops = {
> -	.start = misc_seq_start,
> -	.next  = misc_seq_next,
> -	.stop  = misc_seq_stop,
> -	.show  = misc_seq_show,
> -};
> +DEFINE_PROC_SHOW_ATTRIBUTE(misc);
>  #endif
>  
> -static int misc_open(struct inode *inode, struct file *file)
> +static int misc_fops_open(struct inode *inode, struct file *file)
>  {
>  	int minor = iminor(inode);
>  	struct miscdevice *c;
> @@ -148,7 +131,7 @@ static struct class *misc_class;
>  
>  static const struct file_operations misc_fops = {
>  	.owner		= THIS_MODULE,
> -	.open		= misc_open,
> +	.open		= misc_fops_open,
>  	.llseek		= noop_llseek,
>  };
>  
> @@ -266,9 +249,11 @@ static char *misc_devnode(struct device *dev, umode_t *mode)
>  static int __init misc_init(void)
>  {
>  	int err;
> +#ifdef CONFIG_PROC_FS
>  	struct proc_dir_entry *ret;
>  
> -	ret = proc_create_seq("misc", 0, NULL, &misc_seq_ops);
> +	ret = proc_create("misc", 0, NULL, &misc_proc_ops);
> +#endif

Any way to do this without the #ifdef in the middle of the function?
Otherwise it's not worth taking this change at all.

thanks,

greg k-h

      reply	other threads:[~2022-04-26 10:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-10 15:16 [PATCH RESEND v2] char: misc:use DEFINE_PROC_SHOW_ATTRIBUTE micro to simplify misc proc_fops Junwen Wu
2022-04-26 10:51 ` Greg KH [this message]

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=YmfOncISX6vjQW2I@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wudaemon@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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