Skip to contentSkip to conversation

irq: clarify logic calculating bogus irqreturn_t values

PATCH New Jeremy Kerr 2 participants 2 messages Feb 16, 2017 IRQ

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irq: clarify logic calculating bogus irqreturn_t values

Although irqreturn_t is an enum, we treat it (and its enumeration constants) as a bitmask.

However, bad_action_ret() uses a less-than operator to determine whether an irqreturn_t falls within allowable bit values, which means we need to know the signededness of an enum type to read the logic, which is implementation-dependent.

This change explicitly uses an unsigned type for the comparison. We do this instead of changing to a bitwise test, as the latter compiles to increased instructions in this hot path.

It looks like we get the correct behaviour currently (bad_action_ret(-1) returns 1), so this is purely a readability fix.

---
 kernel/irq/spurious.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/irq/spurious.c +3 -1
index 5707f97..061ba7e 100644
@@ -175,7 +175,9 @@ static void poll_spurious_irqs(unsigned long dummy)
 
 static inline int bad_action_ret(irqreturn_t action_ret)
 {
-	if (likely(action_ret <= (IRQ_HANDLED | IRQ_WAKE_THREAD)))
+	unsigned int r = action_ret;
+
+	if (likely(r <= (IRQ_HANDLED | IRQ_WAKE_THREAD)))
 		return 0;
 	return 1;
 }
Signature · 1 line
2.7.4
#1 lore raw

[tip:irq/core] genirq: Clarify logic calculating bogus irqreturn_t values

genirq: Clarify logic calculating bogus irqreturn_t values
Commit-ID:  5d4bac9a5f4ef24b2482529bda6661a58e5b5b65
Gitweb:     http://git.kernel.org/tip/5d4bac9a5f4ef24b2482529bda6661a58e5b5b65
Author:     Jeremy Kerr <[email protected]>
AuthorDate: Thu, 16 Feb 2017 12:24:09 +0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 16 Feb 2017 15:32:19 +0100

genirq: Clarify logic calculating bogus irqreturn_t values

Although irqreturn_t is an enum, we treat it (and its enumeration constants) as a bitmask.

However, bad_action_ret() uses a less-than operator to determine whether an irqreturn_t falls within allowable bit values, which means we need to know the signededness of an enum type to read the logic, which is implementation-dependent.

This change explicitly uses an unsigned type for the comparison. We do this instead of changing to a bitwise test, as the latter compiles to increased instructions in this hot path.

It looks like we get the correct behaviour currently (bad_action_ret(-1) returns 1), so this is purely a readability fix.

---
 kernel/irq/spurious.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/irq/spurious.c +3 -1
index 5707f97..061ba7e 100644
@@ -175,7 +175,9 @@ out:
 
 static inline int bad_action_ret(irqreturn_t action_ret)
 {
-	if (likely(action_ret <= (IRQ_HANDLED | IRQ_WAKE_THREAD)))
+	unsigned int r = action_ret;
+
+	if (likely(r <= (IRQ_HANDLED | IRQ_WAKE_THREAD)))
 		return 0;
 	return 1;
 }