Skip to content

Commit 6de8169

Browse files
jhovoldgregkh
authored andcommitted
leds: wm831x-status: fix use-after-free on unbind
commit 47a459e upstream. 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: 8d3b6a4 ("leds: wm831x-status: 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 583d424 commit 6de8169

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/leds/leds-wm831x-status.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,23 @@ static int wm831x_status_probe(struct platform_device *pdev)
283283
drvdata->cdev.blink_set = wm831x_status_blink_set;
284284
drvdata->cdev.groups = wm831x_status_groups;
285285

286-
ret = devm_led_classdev_register(wm831x->dev, &drvdata->cdev);
286+
ret = led_classdev_register(wm831x->dev, &drvdata->cdev);
287287
if (ret < 0) {
288288
dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
289289
return ret;
290290
}
291291

292+
platform_set_drvdata(pdev, drvdata);
293+
294+
return 0;
295+
}
296+
297+
static int wm831x_status_remove(struct platform_device *pdev)
298+
{
299+
struct wm831x_status *drvdata = platform_get_drvdata(pdev);
300+
301+
led_classdev_unregister(&drvdata->cdev);
302+
292303
return 0;
293304
}
294305

@@ -297,6 +308,7 @@ static struct platform_driver wm831x_status_driver = {
297308
.name = "wm831x-status",
298309
},
299310
.probe = wm831x_status_probe,
311+
.remove = wm831x_status_remove,
300312
};
301313

302314
module_platform_driver(wm831x_status_driver);

0 commit comments

Comments
 (0)