Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1454455 > unrolled thread

Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro

Started byFelipe Balbi <felipe.balbi@linux.intel.com>
First post2016-08-02 16:00 +0200
Last post2016-08-03 14:30 +0200
Articles 5 — 4 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro Felipe Balbi <felipe.balbi@linux.intel.com> - 2016-08-02 16:00 +0200
    Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro Marcel Holtmann <marcel@holtmann.org> - 2016-08-02 16:10 +0200
    Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro Marcel Holtmann <marcel@holtmann.org> - 2016-08-02 16:10 +0200
    Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro Michal Nazarewicz <mina86@mina86.com> - 2016-08-03 13:20 +0200
    Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro Oliver Neukum <oneukum@suse.com> - 2016-08-03 14:30 +0200

#1454455 — Re: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro

FromFelipe Balbi <felipe.balbi@linux.intel.com>
Date2016-08-02 16:00 +0200
SubjectRe: [PATCH 0984/1285] Replace numeric parameter like 0444 with macro
Message-ID<s1IoG-5bC-17@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

Baole Ni <baolex.ni@intel.com> writes:

> I find that the developers often just specified the numeric value
> when calling a macro which is defined with a parameter for access permission.
> As we know, these numeric value for access permission have had the corresponding macro,
> and that using macro can improve the robustness and readability of the code,
> thus, I suggest replacing the numeric parameter with the macro.
>
> Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
> Signed-off-by: Baole Ni <baolex.ni@intel.com>
> ---
>  drivers/usb/misc/usbtest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> index 6b978f0..5e81dc3 100644
> --- a/drivers/usb/misc/usbtest.c
> +++ b/drivers/usb/misc/usbtest.c
> @@ -15,7 +15,7 @@
>  /*-------------------------------------------------------------------------*/
>  
>  static int override_alt = -1;
> -module_param_named(alt, override_alt, int, 0644);
> +module_param_named(alt, override_alt, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

line too long. You need to run this series through scripts/checkpatch.pl

-- 
balbi

[toc] | [next] | [standalone]


#1454480

FromMarcel Holtmann <marcel@holtmann.org>
Date2016-08-02 16:10 +0200
Message-ID<s1Iyl-5ut-7@gated-at.bofh.it>
In reply to#1454455
Hi Felipe,

>> I find that the developers often just specified the numeric value
>> when calling a macro which is defined with a parameter for access permission.
>> As we know, these numeric value for access permission have had the corresponding macro,
>> and that using macro can improve the robustness and readability of the code,
>> thus, I suggest replacing the numeric parameter with the macro.
>> 
>> Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
>> Signed-off-by: Baole Ni <baolex.ni@intel.com>
>> ---
>> drivers/usb/misc/usbtest.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
>> index 6b978f0..5e81dc3 100644
>> --- a/drivers/usb/misc/usbtest.c
>> +++ b/drivers/usb/misc/usbtest.c
>> @@ -15,7 +15,7 @@
>> /*-------------------------------------------------------------------------*/
>> 
>> static int override_alt = -1;
>> -module_param_named(alt, override_alt, int, 0644);
>> +module_param_named(alt, override_alt, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
> 
> line too long. You need to run this series through scripts/checkpatch.pl

please don't give them any ideas. Next thing you know and another 1285 patch bomb is coming our way.

Regards

Marcel

[toc] | [prev] | [next] | [standalone]


#1454499

FromMarcel Holtmann <marcel@holtmann.org>
Date2016-08-02 16:10 +0200
Message-ID<s1Iyn-5ut-67@gated-at.bofh.it>
In reply to#1454455
Hi Felipe,

>> I find that the developers often just specified the numeric value
>> when calling a macro which is defined with a parameter for access permission.
>> As we know, these numeric value for access permission have had the corresponding macro,
>> and that using macro can improve the robustness and readability of the code,
>> thus, I suggest replacing the numeric parameter with the macro.
>> 
>> Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
>> Signed-off-by: Baole Ni <baolex.ni@intel.com>
>> ---
>> drivers/usb/misc/usbtest.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
>> index 6b978f0..5e81dc3 100644
>> --- a/drivers/usb/misc/usbtest.c
>> +++ b/drivers/usb/misc/usbtest.c
>> @@ -15,7 +15,7 @@
>> /*-------------------------------------------------------------------------*/
>> 
>> static int override_alt = -1;
>> -module_param_named(alt, override_alt, int, 0644);
>> +module_param_named(alt, override_alt, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
> 
> line too long. You need to run this series through scripts/checkpatch.pl

please don't give them any ideas. Next thing you know and another 1285 patch bomb is coming our way.

Regards

Marcel

[toc] | [prev] | [next] | [standalone]


#1455750

FromMichal Nazarewicz <mina86@mina86.com>
Date2016-08-03 13:20 +0200
Message-ID<s22nn-1Pn-7@gated-at.bofh.it>
In reply to#1454455
On Wed, Aug 03 2016, Oliver Neukum wrote:
> Before we think about that, the basic question whether
>
> S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
>
> is clearer and easier to read than
>
> 0644
>
> must be decided. I would saz no, it is not.

I was about to write the same thing.

I dislike magic numbers just like the next guy, but this replaces
a compact representation of the permissions with a long string of hard
to read, awkwardly abbreviated strings.

On personal note, I can never remember whether ‘u’ means user and ‘o’
means other or ‘u’ means users and ‘o’ means ‘owner’.  In cited case
this is somehow averted because both USR and OTH are present, but what
does ‘S_IRWXU’ mean is a mystery to me.

To my mind, the macros make sense only when testing for particular bit
being set.  Something like:

	if (mode & S_IRUSR && check_if_user_can_read())
		success;

could be argued as better than ‘mode & 0400’ but even than the awkward
abbreviation doesn’t help.  Again, ‘PERM_USER_READABLE’ would be much
better (also for the reason mentioned above).

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»

[toc] | [prev] | [next] | [standalone]


#1455779

FromOliver Neukum <oneukum@suse.com>
Date2016-08-03 14:30 +0200
Message-ID<s22nn-1Pn-9@gated-at.bofh.it>
In reply to#1454455
On Tue, 2016-08-02 at 16:54 +0300, Felipe Balbi wrote:
> Baole Ni <baolex.ni@intel.com> writes:
> 
> > I find that the developers often just specified the numeric value
> > when calling a macro which is defined with a parameter for access permission.
> > As we know, these numeric value for access permission have had the corresponding macro,
> > and that using macro can improve the robustness and readability of the code,
> > thus, I suggest replacing the numeric parameter with the macro.
> >
> > Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
> > Signed-off-by: Baole Ni <baolex.ni@intel.com>
> > ---
> >  drivers/usb/misc/usbtest.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> > index 6b978f0..5e81dc3 100644
> > --- a/drivers/usb/misc/usbtest.c
> > +++ b/drivers/usb/misc/usbtest.c
> > @@ -15,7 +15,7 @@
> >  /*-------------------------------------------------------------------------*/
> >  
> >  static int override_alt = -1;
> > -module_param_named(alt, override_alt, int, 0644);
> > +module_param_named(alt, override_alt, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
> 
> line too long. You need to run this series through scripts/checkpatch.pl
> 

Before we think about that, the basic question whether

S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH

is clearer and easier to read than

0644

must be decided. I would saz no, it is not.

	Regards
		Oliver

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web