Skip to content

Commit

Permalink
leds: netxbig: fix attribute-creation race
Browse files Browse the repository at this point in the history
Use the attribute groups of the led-class to create the sata attribute
during probe in order to avoid racing with userspace.

[[email protected]: clean up return led_classdev_register()]

Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
  • Loading branch information
jhovold authored and cooloney committed Jun 25, 2014
1 parent 35c1649 commit 588a6a9
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions drivers/leds/leds-netxbig.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,14 @@ static ssize_t netxbig_led_sata_show(struct device *dev,

static DEVICE_ATTR(sata, 0644, netxbig_led_sata_show, netxbig_led_sata_store);

static struct attribute *netxbig_led_attrs[] = {
&dev_attr_sata.attr,
NULL
};
ATTRIBUTE_GROUPS(netxbig_led);

static void delete_netxbig_led(struct netxbig_led_data *led_dat)
{
if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
led_classdev_unregister(&led_dat->cdev);
}

Expand All @@ -306,7 +310,6 @@ create_netxbig_led(struct platform_device *pdev,
const struct netxbig_led *template)
{
struct netxbig_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
int ret;

spin_lock_init(&led_dat->lock);
led_dat->gpio_ext = pdata->gpio_ext;
Expand All @@ -327,28 +330,20 @@ create_netxbig_led(struct platform_device *pdev,
led_dat->sata = 0;
led_dat->cdev.brightness = LED_OFF;
led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
/*
* If available, expose the SATA activity blink capability through
* a "sata" sysfs attribute.
*/
if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
led_dat->cdev.groups = netxbig_led_groups;
led_dat->mode_addr = template->mode_addr;
led_dat->mode_val = template->mode_val;
led_dat->bright_addr = template->bright_addr;
led_dat->bright_max = (1 << pdata->gpio_ext->num_data) - 1;
led_dat->timer = pdata->timer;
led_dat->num_timer = pdata->num_timer;

ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
if (ret < 0)
return ret;

/*
* If available, expose the SATA activity blink capability through
* a "sata" sysfs attribute.
*/
if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE) {
ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
if (ret)
led_classdev_unregister(&led_dat->cdev);
}

return ret;
return led_classdev_register(&pdev->dev, &led_dat->cdev);
}

static int netxbig_led_probe(struct platform_device *pdev)
Expand Down

0 comments on commit 588a6a9

Please sign in to comment.