Skip to contentSkip to conversation

Replace numeric parameter like 0444 with macro

PATCH NAK Baole Ni 3 participants 3 messages Aug 2, 2016

Subsystems (3)
lore
Share & tools
lore

Baole Ni

author
#0 lore raw

PATCH 34/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.

---
 arch/x86/kvm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu.c +1 -1
index def97b3..ce4f512 100644
@@ -65,7 +65,7 @@ enum {
 
 #ifdef MMU_DEBUG
 static bool dbg = 0;
-module_param(dbg, bool, 0644);
+module_param(dbg, bool, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
 #define pgprintk(x...) do { if (dbg) printk(x); } while (0)
 #define rmap_printk(x...) do { if (dbg) printk(x); } while (0)
Signature · 1 line
2.9.2
#1 lore raw

2016-08-02 18:36+0800, Baole Ni:

arch/x86/kvm/mmu.c enum { · line 65

Quoted 13 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.

---

arch/x86/kvm/mmu.c +1 -1
@@ -65,7 +65,7 @@ enum {
-module_param(dbg, bool, 0644);
+module_param(dbg, bool, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

Please change to "S_IWUSR | S_IRUGO".
0444 -> S_IRUGO should also be applied to other kvm patches.

The result is still less readable than 0644 for me, because octal numbers are practically never used outside of well known access permissions and those macros have to be read painfully carefully, but macros avoid an arbitrary cutoff from flags that might not be known by heart by all developers, maybe starting at S_ISVTX.

Btw. the posting could be improved with a cover letter that would link all patches to it; the series will be easier to handle in mail clients and there will be a clear place for common discussion about the patchset. Optionally merge related patches; one patch per subsystem would be ideal.

#2 lore raw
Quoted 5 lines · Radim Krčmář

Btw. the posting could be improved with a cover letter that would link all patches to it; the series will be easier to handle in mail clients and there will be a clear place for common discussion about the patchset. Optionally merge related patches; one patch per subsystem would be ideal.

If this should be done at all (which I don't think so, the octal representation looks actually much more straightforward than the cryptic macros), it should be scripted (preferably in coccinelle) and sent out as a script to run on the whole tree at higher maintainer levels.

Signature · 2 lines
Jiri Kosina
SUSE Labs