Replace numeric parameter like 0444 with macro
PATCH 984/1285 Replace numeric parameter like 0444 with macro
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.
--- drivers/usb/misc/usbtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/usbtest.c +1 -1
@@ -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 );MODULE_PARM_DESC (alt,">= 0 to override altsetting selection" );static void complicated_callback (struct urb *urb);
Signature · 1 line
2.9.2
Quoted 17 lines · Baole Ni
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 <[email protected]>Signed-off-by Baole Ni <[email protected]>--- drivers/usb/misc/usbtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/misc/usbtest.c +0
-0
drivers/usb/misc/usbtest.c line 18
Quoted 5 lines
drivers/usb/misc/usbtest.c +1
-1@@ -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
Signature · 1 line
balbi
Hi Felipe,
Quoted 19 lines
Quoted 19 lines
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 <[email protected]>Signed-off-by Baole Ni <[email protected]>---
drivers/usb/misc/usbtest.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/misc/usbtest.c +0
-0@@ -15,7 +15,7 @@/*-------------------------------------------------------------------------*/
Quoted 5 lines
drivers/usb/misc/usbtest.c line 18
Quoted 3 lines
drivers/usb/misc/usbtest.c +1
-1static 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
Hi Felipe,
Quoted 19 lines
Quoted 19 lines
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 <[email protected]>Signed-off-by Baole Ni <[email protected]>---
drivers/usb/misc/usbtest.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/misc/usbtest.c +0
-0@@ -15,7 +15,7 @@/*-------------------------------------------------------------------------*/
Quoted 5 lines
drivers/usb/misc/usbtest.c line 18
Quoted 3 lines
drivers/usb/misc/usbtest.c +1
-1static 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
Quoted 21 lines · Felipe Balbi
Quoted 19 lines · Baole Ni
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 <[email protected]>Signed-off-by Baole Ni <[email protected]>--- drivers/usb/misc/usbtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/misc/usbtest.c +0
-0@@ -15,7 +15,7 @@/*-------------------------------------------------------------------------*/
Quoted 6 lines
drivers/usb/misc/usbtest.c line 18
Quoted 3 lines
drivers/usb/misc/usbtest.c +1
-1static 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
Quoted 9 lines · Oliver Neukum
Before we think about that, the basic question whether
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTHis 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).
Signature · 3 lines
Best regards ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ «If at first you don’t succeed, give up skydiving»