linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: ps2-gpio - flush TX work when closing port
@ 2019-02-07 22:27 Dmitry Torokhov
  2019-02-07 22:31 ` Dmitry Torokhov
  2019-02-07 23:03 ` Sven Van Asbroeck
  0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2019-02-07 22:27 UTC (permalink / raw)
  To: linux-input; +Cc: Sven Van Asbroeck, Danilo Krummrich, linux-kernel

To ensure that TX work is not running after serio port has been torn down,
let's flush it when closing the port.

Reported-by: Sven Van Asbroeck <thesven73@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/serio/ps2-gpio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c
index c62cceb97bb1..9e1dbde2e15b 100644
--- a/drivers/input/serio/ps2-gpio.c
+++ b/drivers/input/serio/ps2-gpio.c
@@ -76,6 +76,7 @@ static void ps2_gpio_close(struct serio *serio)
 {
 	struct ps2_gpio_data *drvdata = serio->port_data;
 
+	flush_work(&drvdata->tx_work.work);
 	disable_irq(drvdata->irq);
 }
 
-- 
2.20.1.611.gfbb209baf1-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Input: ps2-gpio - flush TX work when closing port
  2019-02-07 22:27 [PATCH] Input: ps2-gpio - flush TX work when closing port Dmitry Torokhov
@ 2019-02-07 22:31 ` Dmitry Torokhov
  2019-02-07 23:03 ` Sven Van Asbroeck
  1 sibling, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2019-02-07 22:31 UTC (permalink / raw)
  To: linux-input; +Cc: Sven Van Asbroeck, Danilo Krummrich, linux-kernel

On Thu, Feb 07, 2019 at 02:27:40PM -0800, Dmitry Torokhov wrote:
> To ensure that TX work is not running after serio port has been torn down,
> let's flush it when closing the port.
> 
> Reported-by: Sven Van Asbroeck <thesven73@gmail.com>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/serio/ps2-gpio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c
> index c62cceb97bb1..9e1dbde2e15b 100644
> --- a/drivers/input/serio/ps2-gpio.c
> +++ b/drivers/input/serio/ps2-gpio.c
> @@ -76,6 +76,7 @@ static void ps2_gpio_close(struct serio *serio)
>  {
>  	struct ps2_gpio_data *drvdata = serio->port_data;
>  
> +	flush_work(&drvdata->tx_work.work);

Ah, we have flush_delayed_work() now, I'll change it before committing
once we agree on the patch in principle.

>  	disable_irq(drvdata->irq);
>  }
>  
> -- 
> 2.20.1.611.gfbb209baf1-goog
> 
> 
> -- 
> Dmitry

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Input: ps2-gpio - flush TX work when closing port
  2019-02-07 22:27 [PATCH] Input: ps2-gpio - flush TX work when closing port Dmitry Torokhov
  2019-02-07 22:31 ` Dmitry Torokhov
@ 2019-02-07 23:03 ` Sven Van Asbroeck
  2019-02-08  7:31   ` Dmitry Torokhov
  1 sibling, 1 reply; 6+ messages in thread
From: Sven Van Asbroeck @ 2019-02-07 23:03 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, Danilo Krummrich, Linux Kernel Mailing List

On Thu, Feb 7, 2019 at 5:27 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> +       flush_work(&drvdata->tx_work.work);

Would cancel_work_sync() be better than flush_work() ?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Input: ps2-gpio - flush TX work when closing port
  2019-02-07 23:03 ` Sven Van Asbroeck
@ 2019-02-08  7:31   ` Dmitry Torokhov
  2019-02-08 15:51     ` Danilo Krummrich
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2019-02-08  7:31 UTC (permalink / raw)
  To: Sven Van Asbroeck
  Cc: linux-input, Danilo Krummrich, Linux Kernel Mailing List

On Thu, Feb 07, 2019 at 06:03:03PM -0500, Sven Van Asbroeck wrote:
> On Thu, Feb 7, 2019 at 5:27 PM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> >
> > +       flush_work(&drvdata->tx_work.work);
> 
> Would cancel_work_sync() be better than flush_work() ?

No, because we want to have interrupt and gpios in a consistent state.
If we cancel then we need to see if we should disable it or it may
already be disabled, etc. This way we know it is enabled after
flush_delayed_work() returns, and we need to disable it.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Input: ps2-gpio - flush TX work when closing port
  2019-02-08  7:31   ` Dmitry Torokhov
@ 2019-02-08 15:51     ` Danilo Krummrich
  2019-02-08 16:21       ` Sven Van Asbroeck
  0 siblings, 1 reply; 6+ messages in thread
From: Danilo Krummrich @ 2019-02-08 15:51 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Sven Van Asbroeck, linux-input, Linux Kernel Mailing List

On 2019-02-08 08:31, Dmitry Torokhov wrote:
> On Thu, Feb 07, 2019 at 06:03:03PM -0500, Sven Van Asbroeck wrote:
>> On Thu, Feb 7, 2019 at 5:27 PM Dmitry Torokhov
>> <dmitry.torokhov@gmail.com> wrote:
>> >
>> > +       flush_work(&drvdata->tx_work.work);
>> 
>> Would cancel_work_sync() be better than flush_work() ?
> 
> No, because we want to have interrupt and gpios in a consistent state.
> If we cancel then we need to see if we should disable it or it may
> already be disabled, etc. This way we know it is enabled after
> flush_delayed_work() returns, and we need to disable it.
> 
> Thanks.

I agree with Dmitry - thanks for the fix.

Acked-by: Danilo Krummrich <danilokrummrich@dk-develop.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Input: ps2-gpio - flush TX work when closing port
  2019-02-08 15:51     ` Danilo Krummrich
@ 2019-02-08 16:21       ` Sven Van Asbroeck
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Van Asbroeck @ 2019-02-08 16:21 UTC (permalink / raw)
  To: Danilo Krummrich; +Cc: Dmitry Torokhov, linux-input, Linux Kernel Mailing List

On Fri, Feb 8, 2019 at 10:51 AM Danilo Krummrich
<danilokrummrich@dk-develop.de> wrote:
>
> I agree with Dmitry
>

So do I, you guys are absolutely right.
As far as I can see, this patch fixes the user-after-free.
So, after Dmitry changes flush_work() to flush_delayed_work() :

Reviewed-by: Sven Van Asbroeck <TheSven73@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-02-08 16:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 22:27 [PATCH] Input: ps2-gpio - flush TX work when closing port Dmitry Torokhov
2019-02-07 22:31 ` Dmitry Torokhov
2019-02-07 23:03 ` Sven Van Asbroeck
2019-02-08  7:31   ` Dmitry Torokhov
2019-02-08 15:51     ` Danilo Krummrich
2019-02-08 16:21       ` Sven Van Asbroeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).