Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: lm3550: 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>

authored by

Johan Hovold and committed by
Bryan Wu
74c85039 d0d480cc

+7 -13
+7 -13
drivers/leds/leds-lm3530.c
··· 400 400 } 401 401 static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set); 402 402 403 + static struct attribute *lm3530_attrs[] = { 404 + &dev_attr_mode.attr, 405 + NULL 406 + }; 407 + ATTRIBUTE_GROUPS(lm3530); 408 + 403 409 static int lm3530_probe(struct i2c_client *client, 404 410 const struct i2c_device_id *id) 405 411 { ··· 442 436 drvdata->led_dev.name = LM3530_LED_DEV; 443 437 drvdata->led_dev.brightness_set = lm3530_brightness_set; 444 438 drvdata->led_dev.max_brightness = MAX_BRIGHTNESS; 439 + drvdata->led_dev.groups = lm3530_groups; 445 440 446 441 i2c_set_clientdata(client, drvdata); 447 442 ··· 468 461 return err; 469 462 } 470 463 471 - err = device_create_file(drvdata->led_dev.dev, &dev_attr_mode); 472 - if (err < 0) { 473 - dev_err(&client->dev, "File device creation failed: %d\n", err); 474 - err = -ENODEV; 475 - goto err_create_file; 476 - } 477 - 478 464 return 0; 479 - 480 - err_create_file: 481 - led_classdev_unregister(&drvdata->led_dev); 482 - return err; 483 465 } 484 466 485 467 static int lm3530_remove(struct i2c_client *client) 486 468 { 487 469 struct lm3530_data *drvdata = i2c_get_clientdata(client); 488 - 489 - device_remove_file(drvdata->led_dev.dev, &dev_attr_mode); 490 470 491 471 lm3530_led_disable(drvdata); 492 472 led_classdev_unregister(&drvdata->led_dev);