Skip to contentSkip to conversation

scripts: checkpatch.pl: remove obsolete in_atomic rule

RFC PATCH In review Yang Shi 3 participants 5 messages Nov 3, 2017 – Nov 6, 2017 Checkpatch

lore
Share & tools
lore

Yang Shi

author
#0 lore raw

RFC PATCH 1/1 scripts: checkpatch.pl: remove obsolete in_atomic rule

checkpatch.pl still reports the below in_atomic warning:

WARNING: use of in_atomic() is incorrect outside core kernel code
+ if (in_atomic())

But, in_atomic() has been used outside kernel dir for a long time, and even drivers. So, remove the obsolete rule even though they can be ignored.

CC Andrew Morton <[email protected]>

---
Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway it sounds not make sense to keep invalid rule.

 scripts/checkpatch.pl | 11 -----------
 1 file changed, 11 deletions(-)
scripts/checkpatch.pl +0 -11
index 8b80bac..e8cf94f 100755
@@ -6231,17 +6231,6 @@ sub process {
 			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
 		}
 
-# whine mightly about in_atomic
-		if ($line =~ /\bin_atomic\s*\(/) {
-			if ($realfile =~ m@^drivers/@) {
-				ERROR("IN_ATOMIC",
-				      "do not use in_atomic in drivers\n" . $herecurr);
-			} elsif ($realfile !~ m@^kernel/@) {
-				WARN("IN_ATOMIC",
-				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
-			}
-		}
-
 # whine about ACCESS_ONCE
 		if ($^V && $^V ge 5.10.0 &&
 		    $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 8 lines · Yang Shi

checkpatch.pl still reports the below in_atomic warning:

WARNING: use of in_atomic() is incorrect outside core kernel code
+ if (in_atomic())

But, in_atomic() has been used outside kernel dir for a long time, and even drivers. So, remove the obsolete rule even though they can be ignored.

Removing in_atomic() from checkpatch does not make sense without also updating include/linux/preempt.h

Jonathon Corbet added this comment in

commit 8c703d35fa91911dd92a18c31a718853f483ad80

Author: Jonathan Corbet <[email protected]>
Date:   Fri Mar 28 14:15:49 2008 -0700

in_atomic(): document why it is unsuitable for general use

Discourage people from inappropriately using in_atomic()

---
 include/linux/hardirq.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/hardirq.h +7 -0
index 49829988bfa0..897f723bd222 100644
@@ -72,6 +72,13 @@
 #define in_softirq()           (softirq_count())
 #define in_interrupt()         (irq_count())
 
+/*
+ * Are we running in atomic context?  WARNING: this macro cannot
+ * always detect atomic context; in particular, it cannot know about
+ * held spinlocks in non-preemptible kernels.  Thus it should not be
+ * used in the general case to determine whether sleeping is possible.
+ * Do not use in_atomic() in driver code.
+ */
 

Maybe he remembers why...

Quoted 31 lines
CC Andrew Morton <[email protected]>

---
Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway it sounds not make sense to keep invalid rule.

 scripts/checkpatch.pl | 11 -----------
 1 file changed, 11 deletions(-)
scripts/checkpatch.pl +0 -11
index 8b80bac..e8cf94f 100755
@@ -6231,17 +6231,6 @@ sub process {
 			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
 		}
 
-# whine mightly about in_atomic
-		if ($line =~ /\bin_atomic\s*\(/) {
-			if ($realfile =~ m@^drivers/@) {
-				ERROR("IN_ATOMIC",
-				      "do not use in_atomic in drivers\n" . $herecurr);
-			} elsif ($realfile !~ m@^kernel/@) {
-				WARN("IN_ATOMIC",
-				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
-			}
-		}
-
 # whine about ACCESS_ONCE
 		if ($^V && $^V ge 5.10.0 &&
 		    $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
author
#2 lore raw
Quoted 35 lines · Joe Perches
Quoted 8 lines · Yang Shi

checkpatch.pl still reports the below in_atomic warning:

WARNING: use of in_atomic() is incorrect outside core kernel code
+ if (in_atomic())

But, in_atomic() has been used outside kernel dir for a long time, and even drivers. So, remove the obsolete rule even though they can be ignored.

Removing in_atomic() from checkpatch does not make sense without also updating include/linux/preempt.h

Jonathon Corbet added this comment in

commit 8c703d35fa91911dd92a18c31a718853f483ad80

Author: Jonathan Corbet <[email protected]>
Date:   Fri Mar 28 14:15:49 2008 -0700

in_atomic(): document why it is unsuitable for general use

Discourage people from inappropriately using in_atomic()

---
  include/linux/hardirq.h | 7 +++++++
  1 file changed, 7 insertions(+)
include/linux/hardirq.h +0 -0
index 49829988bfa0..897f723bd222 100644

include/linux/hardirq.h line 78

Quoted 7 lines
include/linux/hardirq.h +4 -0
@@ -72,6 +72,13 @@
  #define in_softirq()           (softirq_count())
  #define in_interrupt()         (irq_count())
 
+/*
+ * Are we running in atomic context?  WARNING: this macro cannot
+ * always detect atomic context; in particular, it cannot know about
+ * held spinlocks in non-preemptible kernels.  Thus it should not be

This part looks changed. CONFIG_PREEMPT_COUNT might be enabled with non-preemptible kernel, so that in_atomic() could know if kernel held spinlocks or not.

Yang

Quoted 37 lines
include/linux/hardirq.h +3 -0
+ * used in the general case to determine whether sleeping is possible.
+ * Do not use in_atomic() in driver code.
+ */
 

Maybe he remembers why...

Quoted 31 lines
CC Andrew Morton <[email protected]>

---
Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway it sounds not make sense to keep invalid rule.

  scripts/checkpatch.pl | 11 -----------
  1 file changed, 11 deletions(-)
scripts/checkpatch.pl +0 -11
index 8b80bac..e8cf94f 100755
@@ -6231,17 +6231,6 @@ sub process {
  			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
  		}
 
-# whine mightly about in_atomic
-		if ($line =~ /\bin_atomic\s*\(/) {
-			if ($realfile =~ m@^drivers/@) {
-				ERROR("IN_ATOMIC",
-				      "do not use in_atomic in drivers\n" . $herecurr);
-			} elsif ($realfile !~ m@^kernel/@) {
-				WARN("IN_ATOMIC",
-				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
-			}
-		}
-
  # whine about ACCESS_ONCE
  		if ($^V && $^V ge 5.10.0 &&
  		    $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
#3 lore raw
In reply to Yang Shi
Quoted 8 lines · Yang Shi

checkpatch.pl still reports the below in_atomic warning:

WARNING: use of in_atomic() is incorrect outside core kernel code
+ if (in_atomic())

But, in_atomic() has been used outside kernel dir for a long time, and even drivers. So, remove the obsolete rule even though they can be ignored.

NAK. in_atomic is tricky and shouldn't be used. I would bet most of the
usage is simply broken. See more http://lkml.kernel.org/r/[email protected]

Quoted 33 lines
CC Andrew Morton <[email protected]>

---
Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway it sounds not make sense to keep invalid rule.

 scripts/checkpatch.pl | 11 -----------
 1 file changed, 11 deletions(-)
scripts/checkpatch.pl +0 -11
index 8b80bac..e8cf94f 100755
@@ -6231,17 +6231,6 @@ sub process {
 			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
 		}
 
-# whine mightly about in_atomic
-		if ($line =~ /\bin_atomic\s*\(/) {
-			if ($realfile =~ m@^drivers/@) {
-				ERROR("IN_ATOMIC",
-				      "do not use in_atomic in drivers\n" . $herecurr);
-			} elsif ($realfile !~ m@^kernel/@) {
-				WARN("IN_ATOMIC",
-				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
-			}
-		}
-
 # whine about ACCESS_ONCE
 		if ($^V && $^V ge 5.10.0 &&
 		    $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko
SUSE Labs
author
#4 lore raw
Quoted 6 lines · Michal Hocko
Quoted 5 lines · Yang Shi

checkpatch.pl still reports the below in_atomic warning:

WARNING: use of in_atomic() is incorrect outside core kernel code
+ if (in_atomic())

Quoted 6 lines
Quoted 3 lines

But, in_atomic() has been used outside kernel dir for a long time, and even drivers. So, remove the obsolete rule even though they can be ignored.

NAK. in_atomic is tricky and shouldn't be used. I would bet most of the
usage is simply broken. See more http://lkml.kernel.org/r/[email protected]

Thanks for following up. Yes, it sounds so. However, there is not a reliable and effective approach to check atomic context for both PREEMPT and !PREEMPT.

Yang

Quoted 35 lines
Quoted 34 lines
CC Andrew Morton <[email protected]>

---
Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway it sounds not make sense to keep invalid rule.

  scripts/checkpatch.pl | 11 -----------
  1 file changed, 11 deletions(-)
scripts/checkpatch.pl +0 -11
index 8b80bac..e8cf94f 100755
@@ -6231,17 +6231,6 @@ sub process {
  			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
  		}
 
-# whine mightly about in_atomic
-		if ($line =~ /\bin_atomic\s*\(/) {
-			if ($realfile =~ m@^drivers/@) {
-				ERROR("IN_ATOMIC",
-				      "do not use in_atomic in drivers\n" . $herecurr);
-			} elsif ($realfile !~ m@^kernel/@) {
-				WARN("IN_ATOMIC",
-				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
-			}
-		}
-
  # whine about ACCESS_ONCE
  		if ($^V && $^V ge 5.10.0 &&
  		    $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
Signature · 1 line
1.8.3.1