]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
leds: bcm63138: Use scopes and guards
authorLinus Walleij <linus.walleij@linaro.org>
Thu, 10 Oct 2024 14:10:51 +0000 (16:10 +0200)
committerLee Jones <lee@kernel.org>
Fri, 11 Oct 2024 07:37:05 +0000 (08:37 +0100)
Use scoped helpers and guards to handle DT node iterations
and spinlocks. This cuts some lines of code and eliminates
common mistakes (such as the missing of_node_put()).

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Link: https://lore.kernel.org/r/20241010-bcm63138-leds-v4-2-cdb80780a555@linaro.org
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/blink/leds-bcm63138.c

index 3a5e0b98bfbcf34262e841c76d1bf2e2a5376d08..374f68f4f277c54356598e8f512219ceff274d58 100644 (file)
@@ -2,6 +2,7 @@
 /*
  * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
  */
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/leds.h>
@@ -125,17 +126,14 @@ static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev,
 {
        struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev);
        struct bcm63138_leds *leds = led->leds;
-       unsigned long flags;
 
-       spin_lock_irqsave(&leds->lock, flags);
+       guard(spinlock_irqsave)(&leds->lock);
 
        bcm63138_leds_enable_led(leds, led, value);
        if (!value)
                bcm63138_leds_set_flash_rate(leds, led, 0);
        else
                bcm63138_leds_set_bright(leds, led, value);
-
-       spin_unlock_irqrestore(&leds->lock, flags);
 }
 
 static int bcm63138_leds_blink_set(struct led_classdev *led_cdev,
@@ -144,7 +142,6 @@ static int bcm63138_leds_blink_set(struct led_classdev *led_cdev,
 {
        struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev);
        struct bcm63138_leds *leds = led->leds;
-       unsigned long flags;
        u8 value;
 
        if (!*delay_on && !*delay_off) {
@@ -179,13 +176,11 @@ static int bcm63138_leds_blink_set(struct led_classdev *led_cdev,
                return -EINVAL;
        }
 
-       spin_lock_irqsave(&leds->lock, flags);
+       guard(spinlock_irqsave)(&leds->lock);
 
        bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS);
        bcm63138_leds_set_flash_rate(leds, led, value);
 
-       spin_unlock_irqrestore(&leds->lock, flags);
-
        return 0;
 }
 
@@ -259,7 +254,6 @@ static int bcm63138_leds_probe(struct platform_device *pdev)
        struct device_node *np = dev_of_node(&pdev->dev);
        struct device *dev = &pdev->dev;
        struct bcm63138_leds *leds;
-       struct device_node *child;
 
        leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL);
        if (!leds)
@@ -280,7 +274,7 @@ static int bcm63138_leds_probe(struct platform_device *pdev)
        bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0);
        bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0);
 
-       for_each_available_child_of_node(np, child) {
+       for_each_available_child_of_node_scoped(np, child) {
                bcm63138_leds_create_led(leds, child);
        }