[RFC v1 3/3] cap11xx: fix potential user-after-free on module unload

From: Sven Van Asbroeck
Date: Mon Feb 04 2019 - 17:10:15 EST


The work which is scheduled by led_classdev->brightness_set() is
potentially left pending or running until after the driver module
is unloaded.

Fix by using resource-controlled version of INIT_WORK().

Signed-off-by: Sven Van Asbroeck <TheSven73@xxxxxxxxxxxxxx>
---
drivers/input/keyboard/cap11xx.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c
index 312916f99597..a92dd8ee9ed7 100644
--- a/drivers/input/keyboard/cap11xx.c
+++ b/drivers/input/keyboard/cap11xx.c
@@ -312,7 +312,11 @@ static int cap11xx_init_leds(struct device *dev,
led->reg = reg;
led->priv = priv;

- INIT_WORK(&led->work, cap11xx_led_work);
+ error = devm_init_work(dev, &led->work, cap11xx_led_work);
+ if (error) {
+ of_node_put(child);
+ return error;
+ }

error = devm_led_classdev_register(dev, &led->cdev);
if (error) {
--
2.17.1