diff options
author | Anshul Garg <aksgarg1989@gmail.com> | 2015-06-25 16:33:12 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-06-25 17:44:36 -0400 |
commit | 3e2b03dad54bbcab5be948629a644d55ce7b5a2e (patch) | |
tree | d9f561ab35d2835dfab9af4f37360762f74310e0 | |
parent | 3e30c11c8a902de350281a0d821e17cdb45ef156 (diff) |
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: Anshul Garg <aksgarg1989@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r-- | drivers/input/input.c | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index f31578423636..78d24990a816 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -677,12 +677,9 @@ static void input_dev_release_keys(struct input_dev *dev) | |||
677 | int code; | 677 | int code; |
678 | 678 | ||
679 | if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { | 679 | if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { |
680 | for (code = 0; code <= KEY_MAX; code++) { | 680 | for_each_set_bit(code, dev->key, KEY_CNT) |
681 | if (is_event_supported(code, dev->keybit, KEY_MAX) && | 681 | input_pass_event(dev, EV_KEY, code, 0); |
682 | __test_and_clear_bit(code, dev->key)) { | 682 | memset(dev->key, 0, sizeof(dev->key)); |
683 | input_pass_event(dev, EV_KEY, code, 0); | ||
684 | } | ||
685 | } | ||
686 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); | 683 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); |
687 | } | 684 | } |
688 | } | 685 | } |
@@ -1626,10 +1623,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env) | |||
1626 | if (!test_bit(EV_##type, dev->evbit)) \ | 1623 | if (!test_bit(EV_##type, dev->evbit)) \ |
1627 | break; \ | 1624 | break; \ |
1628 | \ | 1625 | \ |
1629 | for (i = 0; i < type##_MAX; i++) { \ | 1626 | for_each_set_bit(i, dev->bits##bit, type##_CNT) { \ |
1630 | if (!test_bit(i, dev->bits##bit)) \ | ||
1631 | continue; \ | ||
1632 | \ | ||
1633 | active = test_bit(i, dev->bits); \ | 1627 | active = test_bit(i, dev->bits); \ |
1634 | if (!active && !on) \ | 1628 | if (!active && !on) \ |
1635 | continue; \ | 1629 | continue; \ |
@@ -1980,22 +1974,12 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev) | |||
1980 | 1974 | ||
1981 | events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */ | 1975 | events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */ |
1982 | 1976 | ||
1983 | if (test_bit(EV_ABS, dev->evbit)) { | 1977 | if (test_bit(EV_ABS, dev->evbit)) |
1984 | for (i = 0; i < ABS_CNT; i++) { | 1978 | for_each_set_bit(i, dev->absbit, ABS_CNT) |
1985 | if (test_bit(i, dev->absbit)) { | 1979 | events += input_is_mt_axis(i) ? mt_slots : 1; |
1986 | if (input_is_mt_axis(i)) | ||
1987 | events += mt_slots; | ||
1988 | else | ||
1989 | events++; | ||
1990 | } | ||
1991 | } | ||
1992 | } | ||
1993 | 1980 | ||
1994 | if (test_bit(EV_REL, dev->evbit)) { | 1981 | if (test_bit(EV_REL, dev->evbit)) |
1995 | for (i = 0; i < REL_CNT; i++) | 1982 | events += bitmap_weight(dev->relbit, REL_CNT); |
1996 | if (test_bit(i, dev->relbit)) | ||
1997 | events++; | ||
1998 | } | ||
1999 | 1983 | ||
2000 | /* Make room for KEY and MSC events */ | 1984 | /* Make room for KEY and MSC events */ |
2001 | events += 7; | 1985 | events += 7; |