aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2014-06-25 13:08:49 -0400
committerBryan Wu <cooloney@gmail.com>2014-06-25 18:24:03 -0400
commit35c164998eede9e3d49f51541fcf2e639670fe72 (patch)
treeae03d1ebc5c9f557f6f30411d8dc55d9fdf4e9ac
parentfe29a3b0bb375aeac1c995904369553e62d03d75 (diff)
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>
-rw-r--r--drivers/leds/leds-max8997.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
index f449a8bdddc7..607bc2755aba 100644
--- a/drivers/leds/leds-max8997.c
+++ b/drivers/leds/leds-max8997.c
@@ -229,6 +229,12 @@ static ssize_t max8997_led_store_mode(struct device *dev,
229 229
230static DEVICE_ATTR(mode, 0644, max8997_led_show_mode, max8997_led_store_mode); 230static DEVICE_ATTR(mode, 0644, max8997_led_show_mode, max8997_led_store_mode);
231 231
232static struct attribute *max8997_attrs[] = {
233 &dev_attr_mode.attr,
234 NULL
235};
236ATTRIBUTE_GROUPS(max8997);
237
232static int max8997_led_probe(struct platform_device *pdev) 238static int max8997_led_probe(struct platform_device *pdev)
233{ 239{
234 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); 240 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -253,6 +259,7 @@ static int max8997_led_probe(struct platform_device *pdev)
253 led->cdev.brightness_set = max8997_led_brightness_set; 259 led->cdev.brightness_set = max8997_led_brightness_set;
254 led->cdev.flags |= LED_CORE_SUSPENDRESUME; 260 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
255 led->cdev.brightness = 0; 261 led->cdev.brightness = 0;
262 led->cdev.groups = max8997_groups;
256 led->iodev = iodev; 263 led->iodev = iodev;
257 264
258 /* initialize mode and brightness according to platform_data */ 265 /* initialize mode and brightness according to platform_data */
@@ -281,14 +288,6 @@ static int max8997_led_probe(struct platform_device *pdev)
281 if (ret < 0) 288 if (ret < 0)
282 return ret; 289 return ret;
283 290
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
292 return 0; 291 return 0;
293} 292}
294 293
@@ -296,7 +295,6 @@ static int max8997_led_remove(struct platform_device *pdev)
296{ 295{
297 struct max8997_led *led = platform_get_drvdata(pdev); 296 struct max8997_led *led = platform_get_drvdata(pdev);
298 297
299 device_remove_file(led->cdev.dev, &dev_attr_mode);
300 led_classdev_unregister(&led->cdev); 298 led_classdev_unregister(&led->cdev);
301 299
302 return 0; 300 return 0;