2015-08-26 07:33:13

by Holmberg, Hans

[permalink] [raw]
Subject: [PATCH] Input: only send a syn event when needed in input_dev_release_keys

A SYN event is reported in input_release_keys even if no keys are
released. Stop doing this as the superfluous event can prevent autosleep
if a user has opened a device with EPOLLWAKEUP enabled.

Based on a patch developed by Ting Li <[email protected]>.

Signed-off-by: Hans Holmberg <[email protected]>
---
drivers/input/input.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 78d2499..c748805 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -675,12 +675,18 @@ EXPORT_SYMBOL(input_close_device);
static void input_dev_release_keys(struct input_dev *dev)
{
int code;
+ bool key_released = false;

if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
- for_each_set_bit(code, dev->key, KEY_CNT)
+ for_each_set_bit(code, dev->key, KEY_CNT) {
input_pass_event(dev, EV_KEY, code, 0);
- memset(dev->key, 0, sizeof(dev->key));
- input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
+ key_released = true;
+ }
+
+ if (key_released) {
+ memset(dev->key, 0, sizeof(dev->key));
+ input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
+ }
}
}

--
1.9.1


2015-08-26 20:06:06

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] Input: only send a syn event when needed in input_dev_release_keys

Hi Hans,

On Wed, Aug 26, 2015 at 12:38 AM, Hans Holmberg <[email protected]> wrote:
> A SYN event is reported in input_release_keys even if no keys are
> released. Stop doing this as the superfluous event can prevent autosleep
> if a user has opened a device with EPOLLWAKEUP enabled.
>
> Based on a patch developed by Ting Li <[email protected]>.
>
> Signed-off-by: Hans Holmberg <[email protected]>

We already have a similar commit
00159f19a5057cb779146afce1cceede692af346 in next.

Thanks!

> ---
> drivers/input/input.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 78d2499..c748805 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -675,12 +675,18 @@ EXPORT_SYMBOL(input_close_device);
> static void input_dev_release_keys(struct input_dev *dev)
> {
> int code;
> + bool key_released = false;
>
> if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
> - for_each_set_bit(code, dev->key, KEY_CNT)
> + for_each_set_bit(code, dev->key, KEY_CNT) {
> input_pass_event(dev, EV_KEY, code, 0);
> - memset(dev->key, 0, sizeof(dev->key));
> - input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
> + key_released = true;
> + }
> +
> + if (key_released) {
> + memset(dev->key, 0, sizeof(dev->key));
> + input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
> + }
> }
> }
>
> --
> 1.9.1
>



--
Dmitry

2015-08-27 08:38:32

by Holmberg, Hans

[permalink] [raw]
Subject: RE: [PATCH] Input: only send a syn event when needed in input_dev_release_keys

Hi Dmitry,

> We already have a similar commit
> 00159f19a5057cb779146afce1cceede692af346 in next.

That'll fix the problem. I'll make sure to keep an eye on your tree & -next in the future.
My patch doesn’t add much (it does avoid the memset when there are no bits to clear however)

Cheers!

> > ---
> > drivers/input/input.c | 12 +++++++++---
> > 1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/input/input.c b/drivers/input/input.c index
> > 78d2499..c748805 100644
> > --- a/drivers/input/input.c
> > +++ b/drivers/input/input.c
> > @@ -675,12 +675,18 @@ EXPORT_SYMBOL(input_close_device);
> > static void input_dev_release_keys(struct input_dev *dev) {
> > int code;
> > + bool key_released = false;
> >
> > if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
> > - for_each_set_bit(code, dev->key, KEY_CNT)
> > + for_each_set_bit(code, dev->key, KEY_CNT) {
> > input_pass_event(dev, EV_KEY, code, 0);
> > - memset(dev->key, 0, sizeof(dev->key));
> > - input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
> > + key_released = true;
> > + }
> > +
> > + if (key_released) {
> > + memset(dev->key, 0, sizeof(dev->key));
> > + input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
> > + }
> > }
> > }
> >
> > --
> > 1.9.1
> >
>
>
>
> --
> Dmitry
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?