Commit 3e2b03da authored by Anshul Garg's avatar Anshul Garg Committed by Dmitry Torokhov

Input: use for_each_set_bit() where appropriate

Instead of iterating over all bits in a bitmap and test them individually
let's siwtch to for_each_set_bit() which is more compact and is also
faster.

Also use bitmap_weight() when counting number of set bits.

This also fixes INPUT_DO_TOGGLE() implementation as it should have used
*_CNT as the upper boundary, not *_MAX.
Signed-off-by: default avatarAnshul Garg <aksgarg1989@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 3e30c11c
...@@ -677,12 +677,9 @@ static void input_dev_release_keys(struct input_dev *dev) ...@@ -677,12 +677,9 @@ static void input_dev_release_keys(struct input_dev *dev)
int code; int code;
if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
for (code = 0; code <= KEY_MAX; code++) { for_each_set_bit(code, dev->key, KEY_CNT)
if (is_event_supported(code, dev->keybit, KEY_MAX) &&
__test_and_clear_bit(code, dev->key)) {
input_pass_event(dev, EV_KEY, code, 0); input_pass_event(dev, EV_KEY, code, 0);
} memset(dev->key, 0, sizeof(dev->key));
}
input_pass_event(dev, EV_SYN, SYN_REPORT, 1); input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
} }
} }
...@@ -1626,10 +1623,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env) ...@@ -1626,10 +1623,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
if (!test_bit(EV_##type, dev->evbit)) \ if (!test_bit(EV_##type, dev->evbit)) \
break; \ break; \
\ \
for (i = 0; i < type##_MAX; i++) { \ for_each_set_bit(i, dev->bits##bit, type##_CNT) { \
if (!test_bit(i, dev->bits##bit)) \
continue; \
\
active = test_bit(i, dev->bits); \ active = test_bit(i, dev->bits); \
if (!active && !on) \ if (!active && !on) \
continue; \ continue; \
...@@ -1980,22 +1974,12 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev) ...@@ -1980,22 +1974,12 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */ events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */
if (test_bit(EV_ABS, dev->evbit)) { if (test_bit(EV_ABS, dev->evbit))
for (i = 0; i < ABS_CNT; i++) { for_each_set_bit(i, dev->absbit, ABS_CNT)
if (test_bit(i, dev->absbit)) { events += input_is_mt_axis(i) ? mt_slots : 1;
if (input_is_mt_axis(i))
events += mt_slots;
else
events++;
}
}
}
if (test_bit(EV_REL, dev->evbit)) { if (test_bit(EV_REL, dev->evbit))
for (i = 0; i < REL_CNT; i++) events += bitmap_weight(dev->relbit, REL_CNT);
if (test_bit(i, dev->relbit))
events++;
}
/* Make room for KEY and MSC events */ /* Make room for KEY and MSC events */
events += 7; events += 7;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment