Skip to contentSkip to conversation

Coccinelle cleanups

PATCH In review Jules Irenge 3 participants 8 messages Mar 30, 2020 – Apr 3, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover Coccinelle cleanups

This patch series clean up some warnings by the Coccinelle tool.

Jules Irenge (4):
cpu: Remove Comparison to bool
rcu: Replace 1 by true
genirq: Replace 1 by true
locking/rtmutex: Remove Comparison to bool

 kernel/cpu.c             | 2 +-
 kernel/irq/spurious.c    | 2 +-
 kernel/locking/rtmutex.c | 2 +-
 kernel/rcu/tree.c        | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
Signature · 4 lines
Changes since v2:
- Improve on commit log 
- Correct mistake of mixing two different subsystems patches into one.
2.25.1
#1 lore raw

PATCH v2 1/4 cpu: Remove Comparison to bool

Coccinelle reports a warning inside __cpuhp_state_add_instance_cpuslocked()

WARNING: Comparison to bool

To fix this a comparison to a bool variable to false is removed and replaced with the operator ! before the variable

---
 kernel/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cpu.c +1 -1
index 9c706af713fb..97f8b79ba5f5 100644
@@ -1682,7 +1682,7 @@ int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state,
 	lockdep_assert_cpus_held();
 
 	sp = cpuhp_get_step(state);
-	if (sp->multi_instance == false)
+	if (!sp->multi_instance)
 		return -EINVAL;
 
 	mutex_lock(&cpuhp_state_mutex);
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/4 rcu: Replace 1 by true

In reply to Jules Irenge

Coccinelle reports a warning at use_softirq declaration

WARNING: Assignment of 0/1 to bool variable

The root cause is
use_softirq a variable of bool type is initialised with the integer 1 Replacing 1 with value true solve the issue.

---
 kernel/rcu/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/tree.c +1 -1
index d91c9156fab2..c2ffea31eae8 100644
@@ -100,7 +100,7 @@ static struct rcu_state rcu_state = {
 static bool dump_tree;
 module_param(dump_tree, bool, 0444);
 /* By default, use RCU_SOFTIRQ instead of rcuc kthreads. */
-static bool use_softirq = 1;
+static bool use_softirq = true;
 module_param(use_softirq, bool, 0444);
 /* Control rcu_node-tree auto-balancing at boot time. */
 static bool rcu_fanout_exact;
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH v2 2/4] rcu: Replace 1 by true

Quoted 9 lines · Jules Irenge

Coccinelle reports a warning at use_softirq declaration

WARNING: Assignment of 0/1 to bool variable

The root cause is
use_softirq a variable of bool type is initialised with the integer 1 Replacing 1 with value true solve the issue.

Queued for review and testing, thank you!

Thanx, Paul

Quoted 20 lines
---
 kernel/rcu/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/tree.c +1 -1
index d91c9156fab2..c2ffea31eae8 100644
@@ -100,7 +100,7 @@ static struct rcu_state rcu_state = {
 static bool dump_tree;
 module_param(dump_tree, bool, 0444);
 /* By default, use RCU_SOFTIRQ instead of rcuc kthreads. */
-static bool use_softirq = 1;
+static bool use_softirq = true;
 module_param(use_softirq, bool, 0444);
 /* Control rcu_node-tree auto-balancing at boot time. */
 static bool rcu_fanout_exact;
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 3/4 genirq: Replace 1 by true

In reply to Jules Irenge

Coccinelle reports a warning at noirqdebug declaration

WARNING: Assignment of 0/1 to bool variable

The root cause is that
noirqdebug, a variable of bool type is initialised with the integer 1 Replacing 1 with value true fixes the issue.

---
 kernel/irq/spurious.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/spurious.c +1 -1
index f865e5f4d382..70ba6d55d02a 100644
@@ -431,7 +431,7 @@ bool noirqdebug __read_mostly;
 
 int noirqdebug_setup(char *str)
 {
-	noirqdebug = 1;
+	noirqdebug = true;
 	printk(KERN_INFO "IRQ lockup detection disabled\n");
 
 	return 1;
Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 4/4 locking/rtmutex: Remove Comparison to bool

In reply to Jules Irenge

Coccinelle reports a warning inside __sched rt_mutex_slowunlock()

WARNING: Comparison to bool

To fix this,
a comparison (==) of a bool type function result to value true together with the value are removed.

---
 kernel/locking/rtmutex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/rtmutex.c +1 -1
index 851bbb10819d..7289e7b26be4 100644
@@ -1378,7 +1378,7 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
 	 */
 	while (!rt_mutex_has_waiters(lock)) {
 		/* Drops lock->wait_lock ! */
-		if (unlock_rt_mutex_safe(lock, flags) == true)
+		if (unlock_rt_mutex_safe(lock, flags))
 			return false;
 		/* Relock the rtmutex and try again */
 		raw_spin_lock_irqsave(&lock->wait_lock, flags);
Signature · 1 line
2.25.1
maintainer
#6 lore raw

Re: [PATCH v2 4/4] locking/rtmutex: Remove Comparison to bool

Quoted 3 lines · Jules Irenge

Coccinelle reports a warning inside __sched rt_mutex_slowunlock()

WARNING: Comparison to bool

I don't mind the patch; but WTH is that a WARNING ?!? Superfluous, but definitely not wrong or even dangerous AFAICT.

Quoted 25 lines

To fix this,
a comparison (==) of a bool type function result to value true together with the value are removed.

---
 kernel/locking/rtmutex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/rtmutex.c +1 -1
index 851bbb10819d..7289e7b26be4 100644
@@ -1378,7 +1378,7 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
 	 */
 	while (!rt_mutex_has_waiters(lock)) {
 		/* Drops lock->wait_lock ! */
-		if (unlock_rt_mutex_safe(lock, flags) == true)
+		if (unlock_rt_mutex_safe(lock, flags))
 			return false;
 		/* Relock the rtmutex and try again */
 		raw_spin_lock_irqsave(&lock->wait_lock, flags);
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH v2 4/4] locking/rtmutex: Remove Comparison to bool

Quoted 17 lines · Peter Zijlstra
Quoted 3 lines · Jules Irenge

Coccinelle reports a warning inside __sched rt_mutex_slowunlock()

WARNING: Comparison to bool

I don't mind the patch; but WTH is that a WARNING ?!? Superfluous, but definitely not wrong or even dangerous AFAICT.

Quoted 9 lines

To fix this,
a comparison (==) of a bool type function result to value true together with the value are removed.

---
 kernel/locking/rtmutex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
Quoted 14 lines
kernel/locking/rtmutex.c +1 -2
index 851bbb10819d..7289e7b26be4 100644
@@ -1378,7 +1378,7 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
 	 */
 	while (!rt_mutex_has_waiters(lock)) {
 		/* Drops lock->wait_lock ! */
-		if (unlock_rt_mutex_safe(lock, flags) == true)
+		if (unlock_rt_mutex_safe(lock, flags))
 			return false;
 		/* Relock the rtmutex and try again */
 		raw_spin_lock_irqsave(&lock->wait_lock, flags);
--
Quoted 2 lines

2.25.1

Thanks for the reply, I will take good note.