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

leds: max8997: 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
35c16499 fe29a3b0

+7 -9
+7 -9
drivers/leds/leds-max8997.c
··· 229 229 230 230 static DEVICE_ATTR(mode, 0644, max8997_led_show_mode, max8997_led_store_mode); 231 231 232 + static struct attribute *max8997_attrs[] = { 233 + &dev_attr_mode.attr, 234 + NULL 235 + }; 236 + ATTRIBUTE_GROUPS(max8997); 237 + 232 238 static int max8997_led_probe(struct platform_device *pdev) 233 239 { 234 240 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); ··· 259 253 led->cdev.brightness_set = max8997_led_brightness_set; 260 254 led->cdev.flags |= LED_CORE_SUSPENDRESUME; 261 255 led->cdev.brightness = 0; 256 + led->cdev.groups = max8997_groups; 262 257 led->iodev = iodev; 263 258 264 259 /* initialize mode and brightness according to platform_data */ ··· 288 281 if (ret < 0) 289 282 return ret; 290 283 291 - ret = device_create_file(led->cdev.dev, &dev_attr_mode); 292 - if (ret != 0) { 293 - dev_err(&pdev->dev, 294 - "failed to create file: %d\n", ret); 295 - led_classdev_unregister(&led->cdev); 296 - return ret; 297 - } 298 - 299 284 return 0; 300 285 } 301 286 ··· 295 296 { 296 297 struct max8997_led *led = platform_get_drvdata(pdev); 297 298 298 - device_remove_file(led->cdev.dev, &dev_attr_mode); 299 299 led_classdev_unregister(&led->cdev); 300 300 301 301 return 0;