scripts: checkpatch.pl: remove obsolete in_atomic rule
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.
---
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
@@ -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
Joe Perches
maintainerQuoted 8 lines · Yang Shi
checkpatch.pl still reports the below
in_atomicwarning: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
@@ -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
Signed-off-by Yang Shi <[email protected]>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@@ -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)?/) {
Quoted 35 lines · Joe Perches
Quoted 8 lines · Yang Shi
checkpatch.pl still reports the below
in_atomicwarning: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 updatinginclude/linux/preempt.hJonathon Corbet added this comment in
commit
8c703d35fa91911dd92a18c31a718853f483ad80Author: Jonathan Corbet <[email protected]> Date: Fri Mar 28 14:15:49 2008 -0700
in_atomic(): document why it is unsuitable for general useDiscourage people from inappropriately using
in_atomic()Signed-off-by Jonathan Corbet <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>--- include/linux/hardirq.h | 7 +++++++ 1 file changed, 7 insertions(+)include/linux/hardirq.h +0
-0
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
Signed-off-by Yang Shi <[email protected]>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@@ -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)?/) {
Quoted 8 lines · Yang Shi
checkpatch.pl still reports the below
in_atomicwarning: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
Signed-off-by Yang Shi <[email protected]>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@@ -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
Quoted 6 lines · Michal Hocko
Quoted 5 lines · Yang Shi
checkpatch.pl still reports the below
in_atomicwarning: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_atomicis 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
Signed-off-by Yang Shi <[email protected]>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@@ -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