char: misc:use DEFINE_PROC_SHOW_ATTRIBUTE micro to simplify misc proc_fops
PATCH v2 1/1 char: misc:use DEFINE_PROC_SHOW_ATTRIBUTE micro to simplify misc proc_fops
DEFINE_PROC_SHOW_ATTRIBUTE is used to simply seq_file flow ,so we can use it to simplify misc proc_fops.
--- drivers/char/misc.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-)
drivers/char/misc.c +14 -27
@@ -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 misc_class =class_create (THIS_MODULE ,"misc" ); err =PTR_ERR (misc_class);if (IS_ERR (misc_class))
@@ -284,8 +269,10 @@ static int __init misc_init(void)pr_err ("unable to get major %d for misc devices\n" ,MISC_MAJOR );class_destroy (misc_class); fail_remove: +#ifdef CONFIG_PROC_FS if (ret)remove_proc_entry ("misc" ,NULL ); +#endif return err; }subsys_initcall (misc_init);
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 97 lines · wujunwen
DEFINE_PROC_SHOW_ATTRIBUTEis used to simplyseq_fileflow ,so we can use it to simplify miscproc_fops.Signed-off-by wujunwen <[email protected]>--- drivers/char/misc.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-)drivers/char/misc.c +14
-27@@ -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 misc_class =class_create (THIS_MODULE ,"misc" ); err =PTR_ERR (misc_class);if (IS_ERR (misc_class))@@ -284,8 +269,10 @@ static int __init misc_init(void)pr_err ("unable to get major %d for misc devices\n" ,MISC_MAJOR );class_destroy (misc_class); fail_remove: +#ifdef CONFIG_PROC_FS if (ret)remove_proc_entry ("misc" ,NULL ); +#endif return err; }subsys_initcall (misc_init);Signature · 1 line
2.25.1
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/SubmittingPatches for what needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
A message that is not in the archive (sent off-list or not yet received): [email protected]
Greg KH
maintainerQuoted 2 lines · 吴俊文
Dear Greg:
It means I should list the reason why I ptach a new verson?like this:
I do not know what you are referring to, sorry. Also, html email is rejected by the mailing list and out tools, please fix.
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): [email protected]
Greg KH
maintainerQuoted 12 lines · 吴俊文
sorry ,I just send a picture not text.It refers I show list the reason why I patch a newer verson?like this:
<commit message>
...
Signed-off-by Author <author@mail>---
V2 -> V3: Removed redundant helper function
Quoted 9 lines
V1 -> V2: Cleaned up coding style and addressed review comments
path/to/file | 5+++--...
As my bot showed, this is documented in the kernel Documentation/ file for how to do this. And yes, that does look correct.
thanks,
greg k-h