linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] char: misc: minor code cleanup
@ 2017-02-27 22:27 Martin Kaiser
  2017-04-08 16:11 ` Greg Kroah-Hartman
  2017-04-17 18:22 ` [PATCH 1/2 v2] char: misc: move the EXPORT_SYMBOL() declarations Martin Kaiser
  0 siblings, 2 replies; 10+ messages in thread
From: Martin Kaiser @ 2017-02-27 22:27 UTC (permalink / raw)
  To: linux-kernel; +Cc: Martin Kaiser, Arnd Bergmann, Greg Kroah-Hartman

Fix a couple of minor issues found by checkpatch.pl:

Add/remove spaces where required.
Move EXPORT_SYMBOL() to the end of the function it refers to.
Set the access mode for the proc entry explicity.
Use pr_warn() instead of printk() without loglevel.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/char/misc.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 8069b36..c2a2048 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -109,7 +109,7 @@ static int misc_seq_open(struct inode *inode, struct file *file)
 };
 #endif
 
-static int misc_open(struct inode * inode, struct file * file)
+static int misc_open(struct inode *inode, struct file *file)
 {
 	int minor = iminor(inode);
 	struct miscdevice *c;
@@ -150,7 +150,7 @@ static int misc_open(struct inode * inode, struct file * file)
 	err = 0;
 	replace_fops(file, new_fops);
 	if (file->f_op->open)
-		err = file->f_op->open(inode,file);
+		err = file->f_op->open(inode, file);
 fail:
 	mutex_unlock(&misc_mtx);
 	return err;
@@ -182,7 +182,7 @@ static int misc_open(struct inode * inode, struct file * file)
  *	failure.
  */
 
-int misc_register(struct miscdevice * misc)
+int misc_register(struct miscdevice *misc)
 {
 	dev_t dev;
 	int err = 0;
@@ -194,6 +194,7 @@ int misc_register(struct miscdevice * misc)
 
 	if (is_dynamic) {
 		int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
+
 		if (i >= DYNAMIC_MINORS) {
 			err = -EBUSY;
 			goto out;
@@ -237,6 +238,7 @@ int misc_register(struct miscdevice * misc)
 	mutex_unlock(&misc_mtx);
 	return err;
 }
+EXPORT_SYMBOL(misc_register);
 
 /**
  *	misc_deregister - unregister a miscellaneous device
@@ -260,8 +262,6 @@ void misc_deregister(struct miscdevice *misc)
 		clear_bit(i, misc_minors);
 	mutex_unlock(&misc_mtx);
 }
-
-EXPORT_SYMBOL(misc_register);
 EXPORT_SYMBOL(misc_deregister);
 
 static char *misc_devnode(struct device *dev, umode_t *mode)
@@ -280,20 +280,20 @@ static int __init misc_init(void)
 	int err;
 	struct proc_dir_entry *ret;
 
-	ret = proc_create("misc", 0, NULL, &misc_proc_fops);
+	ret = proc_create("misc", 0444, NULL, &misc_proc_fops);
 	misc_class = class_create(THIS_MODULE, "misc");
 	err = PTR_ERR(misc_class);
 	if (IS_ERR(misc_class))
 		goto fail_remove;
 
 	err = -EIO;
-	if (register_chrdev(MISC_MAJOR,"misc",&misc_fops))
+	if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
 		goto fail_printk;
 	misc_class->devnode = misc_devnode;
 	return 0;
 
 fail_printk:
-	printk("unable to get major %d for misc devices\n", MISC_MAJOR);
+	pr_warn("unable to get major %d for misc devices\n", MISC_MAJOR);
 	class_destroy(misc_class);
 fail_remove:
 	if (ret)
-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] char: misc: minor code cleanup
  2017-02-27 22:27 [PATCH] char: misc: minor code cleanup Martin Kaiser
@ 2017-04-08 16:11 ` Greg Kroah-Hartman
  2017-04-17 18:22 ` [PATCH 1/2 v2] char: misc: move the EXPORT_SYMBOL() declarations Martin Kaiser
  1 sibling, 0 replies; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-04-08 16:11 UTC (permalink / raw)
  To: Martin Kaiser; +Cc: linux-kernel, Arnd Bergmann

On Mon, Feb 27, 2017 at 11:27:58PM +0100, Martin Kaiser wrote:
> Fix a couple of minor issues found by checkpatch.pl:
> 
> Add/remove spaces where required.
> Move EXPORT_SYMBOL() to the end of the function it refers to.
> Set the access mode for the proc entry explicity.
> Use pr_warn() instead of printk() without loglevel.

Always break up patches to only do 1 thing per patch.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2 v2] char: misc: move the EXPORT_SYMBOL() declarations
  2017-02-27 22:27 [PATCH] char: misc: minor code cleanup Martin Kaiser
  2017-04-08 16:11 ` Greg Kroah-Hartman
@ 2017-04-17 18:22 ` Martin Kaiser
  2017-04-17 18:22   ` [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry Martin Kaiser
  1 sibling, 1 reply; 10+ messages in thread
From: Martin Kaiser @ 2017-04-17 18:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Arnd Bergmann, Martin Kaiser

This fixes a checkpatch warning:
EXPORT_SYMBOL(foo); should immediately follow its function/variable.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
v2:
   separate patch for each checkpatch warning

 drivers/char/misc.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index c9cd1ea..3447b2e 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -238,6 +238,7 @@ int misc_register(struct miscdevice *misc)
 	mutex_unlock(&misc_mtx);
 	return err;
 }
+EXPORT_SYMBOL(misc_register);
 
 /**
  *	misc_deregister - unregister a miscellaneous device
@@ -261,8 +262,6 @@ void misc_deregister(struct miscdevice *misc)
 		clear_bit(i, misc_minors);
 	mutex_unlock(&misc_mtx);
 }
-
-EXPORT_SYMBOL(misc_register);
 EXPORT_SYMBOL(misc_deregister);
 
 static char *misc_devnode(struct device *dev, umode_t *mode)
-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
  2017-04-17 18:22 ` [PATCH 1/2 v2] char: misc: move the EXPORT_SYMBOL() declarations Martin Kaiser
@ 2017-04-17 18:22   ` Martin Kaiser
  2017-04-18  4:31     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Kaiser @ 2017-04-17 18:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Arnd Bergmann, Martin Kaiser

Set the permissions for /proc/misc to 0444 explicitly. At the moment,
we're using 0 and have proc_create_data() convert this to 0444.
This fixes a checkpatch warning.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
v2:
   separate patch for each checkpatch warning

 drivers/char/misc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 3447b2e..3c633d5 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -280,7 +280,7 @@ static int __init misc_init(void)
 	int err;
 	struct proc_dir_entry *ret;
 
-	ret = proc_create("misc", 0, NULL, &misc_proc_fops);
+	ret = proc_create("misc", 0444, NULL, &misc_proc_fops);
 	misc_class = class_create(THIS_MODULE, "misc");
 	err = PTR_ERR(misc_class);
 	if (IS_ERR(misc_class))
-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
  2017-04-17 18:22   ` [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry Martin Kaiser
@ 2017-04-18  4:31     ` Greg Kroah-Hartman
  2017-04-18  7:51       ` Martin Kaiser
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-04-18  4:31 UTC (permalink / raw)
  To: Martin Kaiser; +Cc: linux-kernel, Arnd Bergmann

On Mon, Apr 17, 2017 at 08:22:57PM +0200, Martin Kaiser wrote:
> Set the permissions for /proc/misc to 0444 explicitly. At the moment,
> we're using 0 and have proc_create_data() convert this to 0444.
> This fixes a checkpatch warning.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> ---
> v2:
>    separate patch for each checkpatch warning
> 
>  drivers/char/misc.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index 3447b2e..3c633d5 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -280,7 +280,7 @@ static int __init misc_init(void)
>  	int err;
>  	struct proc_dir_entry *ret;
>  
> -	ret = proc_create("misc", 0, NULL, &misc_proc_fops);
> +	ret = proc_create("misc", 0444, NULL, &misc_proc_fops);

What checkpatch warning does this fix?  0 is a number :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
  2017-04-18  4:31     ` Greg Kroah-Hartman
@ 2017-04-18  7:51       ` Martin Kaiser
  2017-04-18  8:15         ` Greg Kroah-Hartman
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Kaiser @ 2017-04-18  7:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Arnd Bergmann

Thus wrote Greg Kroah-Hartman (gregkh@linuxfoundation.org):

> > -	ret = proc_create("misc", 0, NULL, &misc_proc_fops);
> > +	ret = proc_create("misc", 0444, NULL, &misc_proc_fops);

> What checkpatch warning does this fix?  0 is a number :)

ERROR: Use 4 digit octal (0777) not decimal permissions
#285: FILE: drivers/char/misc.c:285:
+  ret = proc_create("misc", 0, NULL, &misc_proc_fops);

Best regards,

   Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
  2017-04-18  7:51       ` Martin Kaiser
@ 2017-04-18  8:15         ` Greg Kroah-Hartman
  2017-04-18  9:11           ` Martin Kaiser
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-04-18  8:15 UTC (permalink / raw)
  To: Martin Kaiser; +Cc: linux-kernel, Arnd Bergmann

On Tue, Apr 18, 2017 at 09:51:31AM +0200, Martin Kaiser wrote:
> Thus wrote Greg Kroah-Hartman (gregkh@linuxfoundation.org):
> 
> > > -	ret = proc_create("misc", 0, NULL, &misc_proc_fops);
> > > +	ret = proc_create("misc", 0444, NULL, &misc_proc_fops);
> 
> > What checkpatch warning does this fix?  0 is a number :)
> 
> ERROR: Use 4 digit octal (0777) not decimal permissions
> #285: FILE: drivers/char/misc.c:285:
> +  ret = proc_create("misc", 0, NULL, &misc_proc_fops);

Come on now, think about what this is saying.  Is 0 not also an octal
number?

checkpatch requires you to use your brain, it is but a dumb perl
script...

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
  2017-04-18  8:15         ` Greg Kroah-Hartman
@ 2017-04-18  9:11           ` Martin Kaiser
       [not found]             ` <CAHp75Vec84Ltp2oGQwCKv9CwhzTFCu0znR_tmoLstctn_UR88A@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Kaiser @ 2017-04-18  9:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman

Thus wrote Greg Kroah-Hartman (gregkh@linuxfoundation.org):

> > ERROR: Use 4 digit octal (0777) not decimal permissions
> > #285: FILE: drivers/char/misc.c:285:
> > +  ret = proc_create("misc", 0, NULL, &misc_proc_fops);

> Come on now, think about what this is saying.  Is 0 not also an octal
> number?

checkpatch is asking for a 4 digit octal number. And at least for me,
0444 makes it clearer what the permissions actually are. Yes, somewhere
in the code, I can dig up that 0 is changed to 0444...

> checkpatch requires you to use your brain, it is but a dumb perl
> script...

Sorry, I won't be arguing on a personal level.
If you don't like the patch, feel free to reject it. No problem for me.

Do you think checkpatch shouldn't be looking for exactly 4 digits here
(and elsewhere, it has a list of functions with a permission parameter)?

Best regards,

   Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
       [not found]             ` <CAHp75Vec84Ltp2oGQwCKv9CwhzTFCu0znR_tmoLstctn_UR88A@mail.gmail.com>
@ 2017-04-29  7:05               ` Martin Kaiser
  2017-04-30 12:52                 ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Kaiser @ 2017-04-29  7:05 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Greg Kroah-Hartman, linux-kernel

Hello Andy,

Thus wrote Andy Shevchenko (andy.shevchenko@gmail.com):

> On Tue, Apr 18, 2017 at 12:11 PM, Martin Kaiser <martin@kaiser.cx> wrote:

> > checkpatch is asking for a 4 digit octal number. And at least for me,
> > 0444 makes it clearer what the permissions actually are. Yes, somewhere
> > in the code, I can dig up that 0 is changed to 0444...

> Aren't 0 and 0444 different by meaning?

my undestanding is that proc_create() calls proc_create_data(), where

   if ((mode & S_IALLUGO) == 0)
      mode |= S_IRUGO;

sets mode to 0444 when it was 0.

Best regards,
Martin

(added the lkml back to Cc, I removed it by accident in an earlier mail)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry
  2017-04-29  7:05               ` Martin Kaiser
@ 2017-04-30 12:52                 ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2017-04-30 12:52 UTC (permalink / raw)
  To: Martin Kaiser; +Cc: Greg Kroah-Hartman, linux-kernel

On Sat, Apr 29, 2017 at 10:05 AM, Martin Kaiser <martin@kaiser.cx> wrote:
> Thus wrote Andy Shevchenko (andy.shevchenko@gmail.com):
>> On Tue, Apr 18, 2017 at 12:11 PM, Martin Kaiser <martin@kaiser.cx> wrote:

>> Aren't 0 and 0444 different by meaning?
>
> my undestanding is that proc_create() calls proc_create_data(), where
>
>    if ((mode & S_IALLUGO) == 0)
>       mode |= S_IRUGO;
>
> sets mode to 0444 when it was 0.

Ah, okay. Fair enough.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-04-30 12:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 22:27 [PATCH] char: misc: minor code cleanup Martin Kaiser
2017-04-08 16:11 ` Greg Kroah-Hartman
2017-04-17 18:22 ` [PATCH 1/2 v2] char: misc: move the EXPORT_SYMBOL() declarations Martin Kaiser
2017-04-17 18:22   ` [PATCH 2/2 v2] char: misc: use octal permissions for the proc entry Martin Kaiser
2017-04-18  4:31     ` Greg Kroah-Hartman
2017-04-18  7:51       ` Martin Kaiser
2017-04-18  8:15         ` Greg Kroah-Hartman
2017-04-18  9:11           ` Martin Kaiser
     [not found]             ` <CAHp75Vec84Ltp2oGQwCKv9CwhzTFCu0znR_tmoLstctn_UR88A@mail.gmail.com>
2017-04-29  7:05               ` Martin Kaiser
2017-04-30 12:52                 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).