aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2014-06-25 13:08:51 -0400
committerBryan Wu <cooloney@gmail.com>2014-06-25 18:32:11 -0400
commit475f85482663985550e589496bc3c1e09521838a (patch)
treeab5967b79cc723ec2482531f5e621fa3c0f86a2e /drivers/leds
parent588a6a99286ae30afb1339d8bc2163517b1b7dd1 (diff)
leds: ns2: fix attribute-creation race
Use the attribute groups of the led-class to create the sata 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>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-ns2.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index efa625883c83..231993d1fe21 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -185,6 +185,12 @@ static ssize_t ns2_led_sata_show(struct device *dev,
185 185
186static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store); 186static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
187 187
188static struct attribute *ns2_led_attrs[] = {
189 &dev_attr_sata.attr,
190 NULL
191};
192ATTRIBUTE_GROUPS(ns2_led);
193
188static int 194static int
189create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, 195create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
190 const struct ns2_led *template) 196 const struct ns2_led *template)
@@ -219,6 +225,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
219 led_dat->cdev.blink_set = NULL; 225 led_dat->cdev.blink_set = NULL;
220 led_dat->cdev.brightness_set = ns2_led_set; 226 led_dat->cdev.brightness_set = ns2_led_set;
221 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; 227 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
228 led_dat->cdev.groups = ns2_led_groups;
222 led_dat->cmd = template->cmd; 229 led_dat->cmd = template->cmd;
223 led_dat->slow = template->slow; 230 led_dat->slow = template->slow;
224 231
@@ -235,20 +242,11 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
235 if (ret < 0) 242 if (ret < 0)
236 return ret; 243 return ret;
237 244
238 ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
239 if (ret < 0)
240 goto err_free_cdev;
241
242 return 0; 245 return 0;
243
244err_free_cdev:
245 led_classdev_unregister(&led_dat->cdev);
246 return ret;
247} 246}
248 247
249static void delete_ns2_led(struct ns2_led_data *led_dat) 248static void delete_ns2_led(struct ns2_led_data *led_dat)
250{ 249{
251 device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
252 led_classdev_unregister(&led_dat->cdev); 250 led_classdev_unregister(&led_dat->cdev);
253} 251}
254 252