Skip to content

Commit efde0dd

Browse files
jhovoldgregkh
authored andcommitted
leds: 88pm860x: fix use-after-free on unbind
commit eca21c2 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: 375446d ("leds: 88pm860x: 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 ae1cd9f commit efde0dd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/leds/leds-88pm860x.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,33 @@ static int pm860x_led_probe(struct platform_device *pdev)
207207
data->cdev.brightness_set_blocking = pm860x_led_set;
208208
mutex_init(&data->lock);
209209

210-
ret = devm_led_classdev_register(chip->dev, &data->cdev);
210+
ret = led_classdev_register(chip->dev, &data->cdev);
211211
if (ret < 0) {
212212
dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
213213
return ret;
214214
}
215215
pm860x_led_set(&data->cdev, 0);
216+
217+
platform_set_drvdata(pdev, data);
218+
216219
return 0;
217220
}
218221

222+
static int pm860x_led_remove(struct platform_device *pdev)
223+
{
224+
struct pm860x_led *data = platform_get_drvdata(pdev);
225+
226+
led_classdev_unregister(&data->cdev);
227+
228+
return 0;
229+
}
219230

220231
static struct platform_driver pm860x_led_driver = {
221232
.driver = {
222233
.name = "88pm860x-led",
223234
},
224235
.probe = pm860x_led_probe,
236+
.remove = pm860x_led_remove,
225237
};
226238

227239
module_platform_driver(pm860x_led_driver);

0 commit comments

Comments
 (0)