Skip to contentSkip to conversation

Input: joydev - replace ev_match boolean with goto for early exit

PATCH In review Ashton Warner 2 participants 2 messages Jul 9 – Jul 11

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

PATCH 1/1 Input: joydev - replace ev_match boolean with goto for early exit

The joydev_dev_is_absolute_mouse runs unnecessary Event type checks to determine whether a joydev device is an absolute mouse. Change ev_match to a goto statement to exit early.

---
 drivers/input/joydev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/input/joydev.c +6 -6
index 32459fd8a7c1..a726ba0be05b 100644
@@ -819,7 +819,6 @@ static bool joydev_dev_is_blacklisted(struct input_dev *dev)
 static bool joydev_dev_is_absolute_mouse(struct input_dev *dev)
 {
 	DECLARE_BITMAP(jd_scratch, KEY_CNT);
-	bool ev_match = false;
 
 	BUILD_BUG_ON(ABS_CNT > KEY_CNT || EV_CNT > KEY_CNT);
 
@@ -855,20 +854,21 @@ static bool joydev_dev_is_absolute_mouse(struct input_dev *dev)
 	__set_bit(EV_KEY, jd_scratch);
 	__set_bit(EV_SYN, jd_scratch);
 	if (bitmap_equal(jd_scratch, dev->evbit, EV_CNT))
-		ev_match = true;
+		goto ev_match_pass;
 
 	/* HP ILO2, AMI BMC firmware */
 	__set_bit(EV_MSC, jd_scratch);
 	if (bitmap_equal(jd_scratch, dev->evbit, EV_CNT))
-		ev_match = true;
+		goto ev_match_pass;
 
 	/* VMware Virtual USB Mouse, QEMU USB Tablet, ATEN BMC firmware */
 	__set_bit(EV_REL, jd_scratch);
 	if (bitmap_equal(jd_scratch, dev->evbit, EV_CNT))
-		ev_match = true;
+		goto ev_match_pass;
 
-	if (!ev_match)
-		return false;
+	return false;
+
+ev_match_pass:
 
 	bitmap_zero(jd_scratch, ABS_CNT);
 	__set_bit(ABS_X, jd_scratch);
Signature · 1 line
2.55.0
maintainer
#1 lore raw

Hi Ashton,

Quoted 5 lines · Ashton Warner

The joydev_dev_is_absolute_mouse runs unnecessary Event type checks to determine whether a joydev device is an absolute mouse. Change ev_match to a goto statement to exit early.

I think this is one of the cases where I'd avoid using goto. The extra computation is not in hot path and will be unnoticeable.

Thanks.

Signature · 1 line
Dmitry