Skip to content

Commit 35c1649

Browse files
jhovoldcooloney
authored andcommitted
leds: max8997: fix attribute-creation race
Use the attribute groups of the led-class to create the mode 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 fe29a3b commit 35c1649

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎drivers/leds/leds-max8997.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ static ssize_t max8997_led_store_mode(struct device *dev,
229229

230230
static DEVICE_ATTR(mode, 0644, max8997_led_show_mode, max8997_led_store_mode);
231231

232+
static struct attribute *max8997_attrs[] = {
233+
&dev_attr_mode.attr,
234+
NULL
235+
};
236+
ATTRIBUTE_GROUPS(max8997);
237+
232238
static int max8997_led_probe(struct platform_device *pdev)
233239
{
234240
struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -253,6 +259,7 @@ static int max8997_led_probe(struct platform_device *pdev)
253259
led->cdev.brightness_set = max8997_led_brightness_set;
254260
led->cdev.flags |= LED_CORE_SUSPENDRESUME;
255261
led->cdev.brightness = 0;
262+
led->cdev.groups = max8997_groups;
256263
led->iodev = iodev;
257264

258265
/* initialize mode and brightness according to platform_data */
@@ -281,22 +288,13 @@ static int max8997_led_probe(struct platform_device *pdev)
281288
if (ret < 0)
282289
return ret;
283290

284-
ret = device_create_file(led->cdev.dev, &dev_attr_mode);
285-
if (ret != 0) {
286-
dev_err(&pdev->dev,
287-
"failed to create file: %d\n", ret);
288-
led_classdev_unregister(&led->cdev);
289-
return ret;
290-
}
291-
292291
return 0;
293292
}
294293

295294
static int max8997_led_remove(struct platform_device *pdev)
296295
{
297296
struct max8997_led *led = platform_get_drvdata(pdev);
298297

299-
device_remove_file(led->cdev.dev, &dev_attr_mode);
300298
led_classdev_unregister(&led->cdev);
301299

302300
return 0;

0 commit comments

Comments
 (0)