[PATCH v3 05/35] checkpatch: Warn about capability_unsafe() without comment

Marco Elver posted 35 patches 1 week, 6 days ago
[PATCH v3 05/35] checkpatch: Warn about capability_unsafe() without comment
Posted by Marco Elver 1 week, 6 days ago
Warn about applications of capability_unsafe() without a comment, to
encourage documenting the reasoning behind why it was deemed safe.

Signed-off-by: Marco Elver <elver@google.com>
---
 scripts/checkpatch.pl | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e722dd6fa8ef..532075e67a96 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6717,6 +6717,14 @@ sub process {
 			}
 		}
 
+# check for capability_unsafe without a comment.
+		if ($line =~ /\bcapability_unsafe\b/) {
+			if (!ctx_has_comment($first_line, $linenr)) {
+				WARN("CAPABILITY_UNSAFE",
+				     "capability_unsafe without comment\n" . $herecurr);
+			}
+		}
+
 # check of hardware specific defines
 		if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
 			CHK("ARCH_DEFINES",
-- 
2.51.0.384.g4c02a37b29-goog
Re: [PATCH v3 05/35] checkpatch: Warn about capability_unsafe() without comment
Posted by Joe Perches 1 week, 6 days ago
On Thu, 2025-09-18 at 15:59 +0200, Marco Elver wrote:
> Warn about applications of capability_unsafe() without a comment, to
> encourage documenting the reasoning behind why it was deemed safe.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -6717,6 +6717,14 @@ sub process {
>  			}
>  		}
>  
> +# check for capability_unsafe without a comment.
> +		if ($line =~ /\bcapability_unsafe\b/) {
> +			if (!ctx_has_comment($first_line, $linenr)) {
> +				WARN("CAPABILITY_UNSAFE",
> +				     "capability_unsafe without comment\n" . $herecurr);

while most of these are using the same multi-line style
I'd prefer combining and reducing indentation

		if ($line =~ /\bcapability_unsafe\b/ &&
		    !ctx_has_comment($first_line, $linenr)) {
			WARN(etc...