Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35c16499 authored by Johan Hovold's avatar Johan Hovold Committed by Bryan Wu
Browse files

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: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent fe29a3b0
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -229,6 +229,12 @@ static ssize_t max8997_led_store_mode(struct device *dev,

static DEVICE_ATTR(mode, 0644, max8997_led_show_mode, max8997_led_store_mode);

static struct attribute *max8997_attrs[] = {
	&dev_attr_mode.attr,
	NULL
};
ATTRIBUTE_GROUPS(max8997);

static int max8997_led_probe(struct platform_device *pdev)
{
	struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -253,6 +259,7 @@ static int max8997_led_probe(struct platform_device *pdev)
	led->cdev.brightness_set = max8997_led_brightness_set;
	led->cdev.flags |= LED_CORE_SUSPENDRESUME;
	led->cdev.brightness = 0;
	led->cdev.groups = max8997_groups;
	led->iodev = iodev;

	/* initialize mode and brightness according to platform_data */
@@ -281,14 +288,6 @@ static int max8997_led_probe(struct platform_device *pdev)
	if (ret < 0)
		return ret;

	ret = device_create_file(led->cdev.dev, &dev_attr_mode);
	if (ret != 0) {
		dev_err(&pdev->dev,
			"failed to create file: %d\n", ret);
		led_classdev_unregister(&led->cdev);
		return ret;
	}

	return 0;
}

@@ -296,7 +295,6 @@ static int max8997_led_remove(struct platform_device *pdev)
{
	struct max8997_led *led = platform_get_drvdata(pdev);

	device_remove_file(led->cdev.dev, &dev_attr_mode);
	led_classdev_unregister(&led->cdev);

	return 0;