From e41ca3b1eab89f3d50d0910adb7d6f49ac82d604 Mon Sep 17 00:00:00 2001 From: Yangtao Li Date: Wed, 21 Nov 2018 07:31:38 -0500 Subject: leds: powernv: add of_node_put() of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. powernv_led_probe() doesn't do that, so fix it. Signed-off-by: Yangtao Li Signed-off-by: Jacek Anaszewski --- drivers/leds/leds-powernv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'drivers/leds') diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c index b1adbd70ce2e..fbab86cb3cc7 100644 --- a/drivers/leds/leds-powernv.c +++ b/drivers/leds/leds-powernv.c @@ -285,6 +285,7 @@ static int powernv_led_probe(struct platform_device *pdev) struct device_node *led_node; struct powernv_led_common *powernv_led_common; struct device *dev = &pdev->dev; + int rc; led_node = of_find_node_by_path("/ibm,opal/leds"); if (!led_node) { @@ -295,15 +296,20 @@ static int powernv_led_probe(struct platform_device *pdev) powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common), GFP_KERNEL); - if (!powernv_led_common) - return -ENOMEM; + if (!powernv_led_common) { + rc = -ENOMEM; + goto out; + } mutex_init(&powernv_led_common->lock); powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX); platform_set_drvdata(pdev, powernv_led_common); - return powernv_led_classdev(pdev, led_node, powernv_led_common); + rc = powernv_led_classdev(pdev, led_node, powernv_led_common); +out: + of_node_put(led_node); + return rc; } /* Platform driver remove */ -- cgit v1.2.3 From 555fc5ba57908d7c0e4593bc58b2766f5ed5adf5 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 5 Dec 2018 13:50:27 -0600 Subject: leds: 88pm860x: Use of_node_name_eq for node name comparisons Convert string compares of DT node names to use of_node_name_eq helper instead. This removes direct access to the node name pointer. For instances using of_node_cmp, this has the side effect of now using case sensitive comparisons. This should not matter for any FDT based system which this is. Cc: linux-leds@vger.kernel.org Signed-off-by: Rob Herring Acked-by: Pavel Machek Signed-off-by: Jacek Anaszewski --- drivers/leds/leds-88pm860x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/leds') diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c index 77a104d2b124..036d4a536697 100644 --- a/drivers/leds/leds-88pm860x.c +++ b/drivers/leds/leds-88pm860x.c @@ -130,7 +130,7 @@ static int pm860x_led_dt_init(struct platform_device *pdev, return -ENODEV; } for_each_child_of_node(nproot, np) { - if (!of_node_cmp(np->name, data->name)) { + if (of_node_name_eq(np, data->name)) { of_property_read_u32(np, "marvell,88pm860x-iset", &iset); data->iset = PM8606_LED_CURRENT(iset); -- cgit v1.2.3 From b086592e5dcd9cee360f44be801fbcadb24d5c46 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Fri, 7 Dec 2018 11:10:06 +0100 Subject: leds: gpio: Drop unneeded manual of_node assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts the main change of commit bff23714bc36 ("leds: leds-gpio: Set of_node for created LED devices") because of_node assignment is handled by core since commit 7ea79ae86c28 ("leds: gpio: use OF variant of LED registering function"). Basically the code was overwriting the of_node with same value. No functional change expected. Signed-off-by: Krzysztof Kozlowski Tested-by: Rafał Miłecki Signed-off-by: Jacek Anaszewski --- drivers/leds/leds-gpio.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/leds') diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 45e012093865..998f2ff6914d 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -190,7 +190,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) fwnode_handle_put(child); return ERR_PTR(ret); } - led_dat->cdev.dev->of_node = np; priv->num_leds++; } -- cgit v1.2.3 From e5a0436dd08a18834c134ffd08295e36c6f85219 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Fri, 7 Dec 2018 13:32:51 +0100 Subject: leds: pwm: Simplify with resource-managed devm_led_classdev_register() Simplify the exit path with resource-managed version of registering LED class device. The code should be functionally the same, except that on device removal the led_pwm_priv->num_leds is not decremented to zero (which should not have any effect as device is going away). Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jacek Anaszewski --- drivers/leds/leds-pwm.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'drivers/leds') diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index 5d3faae51d59..fcb3e87a9887 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -74,12 +74,6 @@ static inline size_t sizeof_pwm_leds_priv(int num_leds) (sizeof(struct led_pwm_data) * num_leds); } -static void led_pwm_cleanup(struct led_pwm_priv *priv) -{ - while (priv->num_leds--) - led_classdev_unregister(&priv->leds[priv->num_leds].cdev); -} - static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, struct led_pwm *led, struct device_node *child) { @@ -120,7 +114,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, if (!led_data->period && (led->pwm_period_ns > 0)) led_data->period = led->pwm_period_ns; - ret = led_classdev_register(dev, &led_data->cdev); + ret = devm_led_classdev_register(dev, &led_data->cdev); if (ret == 0) { priv->num_leds++; led_pwm_set(&led_data->cdev, led_data->cdev.brightness); @@ -191,25 +185,14 @@ static int led_pwm_probe(struct platform_device *pdev) ret = led_pwm_create_of(&pdev->dev, priv); } - if (ret) { - led_pwm_cleanup(priv); + if (ret) return ret; - } platform_set_drvdata(pdev, priv); return 0; } -static int led_pwm_remove(struct platform_device *pdev) -{ - struct led_pwm_priv *priv = platform_get_drvdata(pdev); - - led_pwm_cleanup(priv); - - return 0; -} - static const struct of_device_id of_pwm_leds_match[] = { { .compatible = "pwm-leds", }, {}, @@ -218,7 +201,6 @@ MODULE_DEVICE_TABLE(of, of_pwm_leds_match); static struct platform_driver led_pwm_driver = { .probe = led_pwm_probe, - .remove = led_pwm_remove, .driver = { .name = "leds_pwm", .of_match_table = of_pwm_leds_match, -- cgit v1.2.3 From cb14e6d6d8f411b7a05f36d1f877450c036d8c56 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Fri, 7 Dec 2018 13:32:52 +0100 Subject: leds: pwm: Use OF variant of LED registering function The PWM leds can be instantiated from Device Tree so pass the respective device node to LED core. This provides the LED system with proper device node and exposes it through uevent. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jacek Anaszewski --- drivers/leds/leds-pwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/leds') diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index fcb3e87a9887..af08bcdc4fd8 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -114,7 +114,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, if (!led_data->period && (led->pwm_period_ns > 0)) led_data->period = led->pwm_period_ns; - ret = devm_led_classdev_register(dev, &led_data->cdev); + ret = devm_of_led_classdev_register(dev, child, &led_data->cdev); if (ret == 0) { priv->num_leds++; led_pwm_set(&led_data->cdev, led_data->cdev.brightness); -- cgit v1.2.3 From c4f7bd4a42758ed42cf7f7a5fd46e0b54ce23ad2 Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Mon, 10 Dec 2018 10:29:57 +0100 Subject: led: triggers: Break the for loop after default trigger is found It is of no avail to continue iterating through registered triggers in the led_trigger_set_default() after the trigger to set has been found. Add "break" statement to fix this omission. Signed-off-by: Jacek Anaszewski Acked-by: Pavel Machek Signed-off-by: Krzysztof Kozlowski --- drivers/leds/led-triggers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/leds') diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 17d73db1456e..52b12e601ebe 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -200,8 +200,10 @@ void led_trigger_set_default(struct led_classdev *led_cdev) down_read(&triggers_list_lock); down_write(&led_cdev->trigger_lock); list_for_each_entry(trig, &trigger_list, next_trig) { - if (!strcmp(led_cdev->default_trigger, trig->name)) + if (!strcmp(led_cdev->default_trigger, trig->name)) { led_trigger_set(led_cdev, trig); + break; + } } up_write(&led_cdev->trigger_lock); up_read(&triggers_list_lock); -- cgit v1.2.3 From 02d31765bb35101d711b862fc619a49857bb9070 Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Mon, 10 Dec 2018 10:29:58 +0100 Subject: led: triggers: Add LED_INIT_DEFAULT_TRIGGER flag Add the flag LED_INIT_DEFAULT_TRIGGER for indicating that trigger being set is a default trigger for the LED class device, and thus it should be initialized with settings provided in the fwnode. Set the flag in the led_trigger_set_default(). It is expected to be cleared in the activate() op of a trigger after trigger fwnode initialization data is parsed and applied. This should happen only once after LED class device registration, to allow leaving triggers in the idle state on re-apply and let the users apply their own settings without interference from the default ones. Signed-off-by: Jacek Anaszewski Acked-by: Pavel Machek Signed-off-by: Krzysztof Kozlowski --- drivers/leds/led-triggers.c | 1 + include/linux/leds.h | 1 + 2 files changed, 2 insertions(+) (limited to 'drivers/leds') diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 52b12e601ebe..f28ce25d24d0 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -201,6 +201,7 @@ void led_trigger_set_default(struct led_classdev *led_cdev) down_write(&led_cdev->trigger_lock); list_for_each_entry(trig, &trigger_list, next_trig) { if (!strcmp(led_cdev->default_trigger, trig->name)) { + led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER; led_trigger_set(led_cdev, trig); break; } diff --git a/include/linux/leds.h b/include/linux/leds.h index 7393a316d9fa..6f05a5816371 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -51,6 +51,7 @@ struct led_classdev { #define LED_PANIC_INDICATOR BIT(20) #define LED_BRIGHT_HW_CHANGED BIT(21) #define LED_RETAIN_AT_SHUTDOWN BIT(22) +#define LED_INIT_DEFAULT_TRIGGER BIT(23) /* set_brightness_work / blink_timer flags, atomic, private. */ unsigned long work_flags; -- cgit v1.2.3 From 8146aace60c7409cc60a1598bc9647a5bbb12eb4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 10 Dec 2018 10:29:59 +0100 Subject: led: triggers: Initialize LED_INIT_DEFAULT_TRIGGER if trigger is brought after class Trigger driver can be initialized after the LED class device driver. In such case led_trigger_set_default() won't be called and flag LED_INIT_DEFAULT_TRIGGER should be set from led_trigger_register(). Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jacek Anaszewski --- drivers/leds/led-triggers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/leds') diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index f28ce25d24d0..2d451b6c24af 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -251,8 +251,10 @@ int led_trigger_register(struct led_trigger *trig) list_for_each_entry(led_cdev, &leds_list, node) { down_write(&led_cdev->trigger_lock); if (!led_cdev->trigger && led_cdev->default_trigger && - !strcmp(led_cdev->default_trigger, trig->name)) + !strcmp(led_cdev->default_trigger, trig->name)) { + led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER; led_trigger_set(led_cdev, trig); + } up_write(&led_cdev->trigger_lock); } up_read(&leds_list_lock); -- cgit v1.2.3