]> git.karo-electronics.de Git - linux-beck.git/commitdiff
leds: lp55xx-common: fix attribute-creation race
authorJohan Hovold <johan@kernel.org>
Wed, 25 Jun 2014 17:08:56 +0000 (10:08 -0700)
committerBryan Wu <cooloney@gmail.com>
Fri, 27 Jun 2014 20:44:05 +0000 (13:44 -0700)
Use the attribute groups of the led-class to create the LED attributes
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>
drivers/leds/leds-lp55xx-common.c

index 3fbfb31602c7070d84966349b47a47c42e3eb1ad..77c26bc32eed561a26c4ccb45b3238e60184d017 100644 (file)
@@ -127,15 +127,12 @@ static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,
                lp55xx_store_current);
 static DEVICE_ATTR(max_current, S_IRUGO , lp55xx_show_max_current, NULL);
 
-static struct attribute *lp55xx_led_attributes[] = {
+static struct attribute *lp55xx_led_attrs[] = {
        &dev_attr_led_current.attr,
        &dev_attr_max_current.attr,
        NULL,
 };
-
-static struct attribute_group lp55xx_led_attr_group = {
-       .attrs = lp55xx_led_attributes
-};
+ATTRIBUTE_GROUPS(lp55xx_led);
 
 static void lp55xx_set_brightness(struct led_classdev *cdev,
                             enum led_brightness brightness)
@@ -176,6 +173,7 @@ static int lp55xx_init_led(struct lp55xx_led *led,
        }
 
        led->cdev.brightness_set = lp55xx_set_brightness;
+       led->cdev.groups = lp55xx_led_groups;
 
        if (pdata->led_config[chan].name) {
                led->cdev.name = pdata->led_config[chan].name;
@@ -185,24 +183,12 @@ static int lp55xx_init_led(struct lp55xx_led *led,
                led->cdev.name = name;
        }
 
-       /*
-        * register led class device for each channel and
-        * add device attributes
-        */
-
        ret = led_classdev_register(dev, &led->cdev);
        if (ret) {
                dev_err(dev, "led register err: %d\n", ret);
                return ret;
        }
 
-       ret = sysfs_create_group(&led->cdev.dev->kobj, &lp55xx_led_attr_group);
-       if (ret) {
-               dev_err(dev, "led sysfs err: %d\n", ret);
-               led_classdev_unregister(&led->cdev);
-               return ret;
-       }
-
        return 0;
 }
 
@@ -520,8 +506,6 @@ void lp55xx_unregister_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
 
        for (i = 0; i < chip->num_leds; i++) {
                each = led + i;
-               sysfs_remove_group(&each->cdev.dev->kobj,
-                                               &lp55xx_led_attr_group);
                led_classdev_unregister(&each->cdev);
                flush_work(&each->brightness_work);
        }