Skip to content

Commit fe29a3b

Browse files
jhovoldcooloney
authored andcommitted
leds: lm3642: fix attribute-creation race
Use the attribute groups of the led-class to create the flash and torch-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>
1 parent 0d25376 commit fe29a3b

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

‎drivers/leds/leds-lm3642.c‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,18 @@ static const struct regmap_config lm3642_regmap = {
313313
.max_register = REG_MAX,
314314
};
315315

316+
static struct attribute *lm3642_flash_attrs[] = {
317+
&dev_attr_strobe_pin.attr,
318+
NULL
319+
};
320+
ATTRIBUTE_GROUPS(lm3642_flash);
321+
322+
static struct attribute *lm3642_torch_attrs[] = {
323+
&dev_attr_torch_pin.attr,
324+
NULL
325+
};
326+
ATTRIBUTE_GROUPS(lm3642_torch);
327+
316328
static int lm3642_probe(struct i2c_client *client,
317329
const struct i2c_device_id *id)
318330
{
@@ -364,35 +376,27 @@ static int lm3642_probe(struct i2c_client *client,
364376
chip->cdev_flash.max_brightness = 16;
365377
chip->cdev_flash.brightness_set = lm3642_strobe_brightness_set;
366378
chip->cdev_flash.default_trigger = "flash";
379+
chip->cdev_flash.groups = lm3642_flash_groups,
367380
err = led_classdev_register((struct device *)
368381
&client->dev, &chip->cdev_flash);
369382
if (err < 0) {
370383
dev_err(chip->dev, "failed to register flash\n");
371384
goto err_out;
372385
}
373-
err = device_create_file(chip->cdev_flash.dev, &dev_attr_strobe_pin);
374-
if (err < 0) {
375-
dev_err(chip->dev, "failed to create strobe-pin file\n");
376-
goto err_create_flash_pin_file;
377-
}
378386

379387
/* torch */
380388
INIT_WORK(&chip->work_torch, lm3642_deferred_torch_brightness_set);
381389
chip->cdev_torch.name = "torch";
382390
chip->cdev_torch.max_brightness = 8;
383391
chip->cdev_torch.brightness_set = lm3642_torch_brightness_set;
384392
chip->cdev_torch.default_trigger = "torch";
393+
chip->cdev_torch.groups = lm3642_torch_groups,
385394
err = led_classdev_register((struct device *)
386395
&client->dev, &chip->cdev_torch);
387396
if (err < 0) {
388397
dev_err(chip->dev, "failed to register torch\n");
389398
goto err_create_torch_file;
390399
}
391-
err = device_create_file(chip->cdev_torch.dev, &dev_attr_torch_pin);
392-
if (err < 0) {
393-
dev_err(chip->dev, "failed to create torch-pin file\n");
394-
goto err_create_torch_pin_file;
395-
}
396400

397401
/* indicator */
398402
INIT_WORK(&chip->work_indicator,
@@ -411,12 +415,8 @@ static int lm3642_probe(struct i2c_client *client,
411415
return 0;
412416

413417
err_create_indicator_file:
414-
device_remove_file(chip->cdev_torch.dev, &dev_attr_torch_pin);
415-
err_create_torch_pin_file:
416418
led_classdev_unregister(&chip->cdev_torch);
417419
err_create_torch_file:
418-
device_remove_file(chip->cdev_flash.dev, &dev_attr_strobe_pin);
419-
err_create_flash_pin_file:
420420
led_classdev_unregister(&chip->cdev_flash);
421421
err_out:
422422
return err;
@@ -428,10 +428,8 @@ static int lm3642_remove(struct i2c_client *client)
428428

429429
led_classdev_unregister(&chip->cdev_indicator);
430430
flush_work(&chip->work_indicator);
431-
device_remove_file(chip->cdev_torch.dev, &dev_attr_torch_pin);
432431
led_classdev_unregister(&chip->cdev_torch);
433432
flush_work(&chip->work_torch);
434-
device_remove_file(chip->cdev_flash.dev, &dev_attr_strobe_pin);
435433
led_classdev_unregister(&chip->cdev_flash);
436434
flush_work(&chip->work_flash);
437435
regmap_write(chip->regmap, REG_ENABLE, 0);

0 commit comments

Comments
 (0)