Skip to content

Commit 6f4aa35

Browse files
jhovoldpavelmachek
authored andcommitted
leds: da903x: fix use-after-free on unbind
Several MFD child drivers register their class devices directly under the parent device. This means you cannot blindly do devres conversions so that deregistration ends up being tied to the parent device, something which leads to use-after-free on driver unbind when the class device is released while still being registered. Fixes: eed1625 ("leds: da903x: Use devm_led_classdev_register") Cc: stable <[email protected]> # 4.6 Cc: Amitoj Kaur Chawla <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent eca21c2 commit 6f4aa35

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/leds/leds-da903x.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,23 @@ static int da903x_led_probe(struct platform_device *pdev)
110110
led->flags = pdata->flags;
111111
led->master = pdev->dev.parent;
112112

113-
ret = devm_led_classdev_register(led->master, &led->cdev);
113+
ret = led_classdev_register(led->master, &led->cdev);
114114
if (ret) {
115115
dev_err(&pdev->dev, "failed to register LED %d\n", id);
116116
return ret;
117117
}
118118

119+
platform_set_drvdata(pdev, led);
120+
121+
return 0;
122+
}
123+
124+
static int da903x_led_remove(struct platform_device *pdev)
125+
{
126+
struct da903x_led *led = platform_get_drvdata(pdev);
127+
128+
led_classdev_unregister(&led->cdev);
129+
119130
return 0;
120131
}
121132

@@ -124,6 +135,7 @@ static struct platform_driver da903x_led_driver = {
124135
.name = "da903x-led",
125136
},
126137
.probe = da903x_led_probe,
138+
.remove = da903x_led_remove,
127139
};
128140

129141
module_platform_driver(da903x_led_driver);

0 commit comments

Comments
 (0)