Skip to contentSkip to conversation

Input: ps2-gpio - flush TX work when closing port

PATCH In review Dmitry Torokhov 3 participants 6 messages Feb 7, 2019 – Feb 8, 2019

Subsystems (2)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

PATCH 1/1 Input: ps2-gpio - flush TX work when closing port

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

---
 drivers/input/serio/ps2-gpio.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/serio/ps2-gpio.c +1 -0
index c62cceb97bb1..9e1dbde2e15b 100644
@@ -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);
 }
 
Signature · 5 lines
2.20.1.611.gfbb209baf1-goog


-- 
Dmitry
author maintainer
#1 lore raw
Quoted 14 lines · Dmitry Torokhov

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

---
 drivers/input/serio/ps2-gpio.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/serio/ps2-gpio.c +0 -0
index c62cceb97bb1..9e1dbde2e15b 100644

drivers/input/serio/ps2-gpio.c static void ps2_gpio_close(struct serio *serio) · line 79

Quoted 4 lines
drivers/input/serio/ps2-gpio.c +1 -0
@@ -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.

Quoted 9 lines
drivers/input/serio/ps2-gpio.c +0 -0
 	disable_irq(drvdata->irq);
 }
 
Signature · 5 lines
2.20.1.611.gfbb209baf1-goog


-- 
Dmitry
Signature · 1 line
Dmitry
author maintainer
#3 lore raw
Quoted 6 lines · Sven Van Asbroeck
Quoted 2 lines · Dmitry Torokhov

+ 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.

Signature · 1 line
Dmitry
#4 lore raw
Quoted 6 lines · Dmitry Torokhov
Quoted 5 lines · Sven Van Asbroeck
Quoted 2 lines · Dmitry Torokhov

+ flush_work(&drvdata->tx_work.work);

Quoted 8 lines
Quoted 1 line

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.

Reviewed-by
#5 lore raw
Quoted 3 lines · Danilo Krummrich

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() :