Skip to content

Commit b2015ed

Browse files
jhovoldcooloney
authored andcommitted
leds: wm831x-status: fix attribute-creation race
Use the attribute groups of the led-class to create the src attribute during probe in order to avoid racing with userspace. Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Bryan Wu <cooloney@gmail.com>
1 parent 67bd8eb commit b2015ed

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

‎drivers/leds/leds-wm831x-status.c‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ static ssize_t wm831x_status_src_store(struct device *dev,
219219

220220
static DEVICE_ATTR(src, 0644, wm831x_status_src_show, wm831x_status_src_store);
221221

222+
static struct attribute *wm831x_status_attrs[] = {
223+
&dev_attr_src.attr,
224+
NULL
225+
};
226+
ATTRIBUTE_GROUPS(wm831x_status);
227+
222228
static int wm831x_status_probe(struct platform_device *pdev)
223229
{
224230
struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
@@ -232,8 +238,7 @@ static int wm831x_status_probe(struct platform_device *pdev)
232238
res = platform_get_resource(pdev, IORESOURCE_REG, 0);
233239
if (res == NULL) {
234240
dev_err(&pdev->dev, "No register resource\n");
235-
ret = -EINVAL;
236-
goto err;
241+
return -EINVAL;
237242
}
238243

239244
drvdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_status),
@@ -284,31 +289,21 @@ static int wm831x_status_probe(struct platform_device *pdev)
284289
drvdata->cdev.default_trigger = pdata.default_trigger;
285290
drvdata->cdev.brightness_set = wm831x_status_set;
286291
drvdata->cdev.blink_set = wm831x_status_blink_set;
292+
drvdata->cdev.groups = wm831x_status_groups;
287293

288294
ret = led_classdev_register(wm831x->dev, &drvdata->cdev);
289295
if (ret < 0) {
290296
dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
291-
goto err_led;
297+
return ret;
292298
}
293299

294-
ret = device_create_file(drvdata->cdev.dev, &dev_attr_src);
295-
if (ret != 0)
296-
dev_err(&pdev->dev,
297-
"No source control for LED: %d\n", ret);
298-
299300
return 0;
300-
301-
err_led:
302-
led_classdev_unregister(&drvdata->cdev);
303-
err:
304-
return ret;
305301
}
306302

307303
static int wm831x_status_remove(struct platform_device *pdev)
308304
{
309305
struct wm831x_status *drvdata = platform_get_drvdata(pdev);
310306

311-
device_remove_file(drvdata->cdev.dev, &dev_attr_src);
312307
led_classdev_unregister(&drvdata->cdev);
313308

314309
return 0;

0 commit comments

Comments
 (0)