Input: joydev - replace ev_match boolean with goto for early exit
Subsystems (2)
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.
Signed-off-by Ashton Warner <[email protected]>
--- drivers/input/joydev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/input/joydev.c +6 -6
@@ -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
Dmitry Torokhov
maintainerHi Ashton,
Quoted 5 lines · Ashton Warner
The
joydev_dev_is_absolute_mouseruns unnecessary Event type checks to determine whether a joydev device is an absolute mouse. Changeev_matchto a goto statement to exit early.Signed-off-by Ashton Warner <[email protected]>
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