Skip to contentSkip to conversation

checkpatch: forbid filesystem accesses from within the kernel

PATCH In review Prakruthi Deepak Heragu 2 participants 2 messages Jul 5, 2018 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: forbid filesystem accesses from within the kernel

As use of sys_open/close/read/write system calls from within the kernel code is inappropriate, an error is triggered if used.

---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)
scripts/checkpatch.pl +7 -0
index a9c0550..e6e7e09 100755
@@ -5372,6 +5372,13 @@ sub process {
 			     "Avoid line continuations in quoted strings\n" . $herecurr);
 		}
 
+# sys_open/read/write/close are not allowed in the kernel
+		if ($line =~ /\b(sys_(?:open|read|write|close))\b/) {
+			ERROR("FILE_OPS",
+			      "$1 is inappropriate in kernel code.\n" .
+			      $herecurr);
+		}
+
 # warn about #if 0
 		if ($line =~ /^.\s*\#\s*if\s+0\b/) {
 			CHK("REDUNDANT_CODE",
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#1 lore raw
Quoted 2 lines · Prakruthi Deepak Heragu

As use of sys_open/close/read/write system calls from within the kernel code is inappropriate, an error is triggered if used.

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 5381

Quoted 11 lines
scripts/checkpatch.pl +7 -0
@@ -5372,6 +5372,13 @@ sub process {
 			     "Avoid line continuations in quoted strings\n" . $herecurr);
 		}
 
+# sys_open/read/write/close are not allowed in the kernel
+		if ($line =~ /\b(sys_(?:open|read|write|close))\b/) {
+			ERROR("FILE_OPS",
+			      "$1 is inappropriate in kernel code.\n" .
+			      $herecurr);
+		}
+

Is this really useful?

As far as I can tell, this would only give
false positives on all existing kernel code.