* [PATCH] leds: lm3642: use guard to simplify locking
@ 2026-03-11 4:00 Richard Lyu
2026-03-19 15:15 ` Lee Jones
0 siblings, 1 reply; 2+ messages in thread
From: Richard Lyu @ 2026-03-11 4:00 UTC (permalink / raw)
To: Lee Jones; +Cc: Pavel Machek, linux-leds, linux-kernel, Richard Lyu
The mutex_lock()/mutex_unlock() pattern requires explicitly pairing
lock and unlock calls. Use guard(mutex) instead so the lock is
automatically released when the scope exits.
Convert to guard(mutex) in lm3642_torch_brightness_set(),
lm3642_strobe_brightness_set(), and lm3642_indicator_brightness_set().
Add #include <linux/cleanup.h> to support scoped guards.
Signed-off-by: Richard Lyu <richard.lyu@suse.com>
---
drivers/leds/leds-lm3642.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/leds/leds-lm3642.c b/drivers/leds/leds-lm3642.c
index 61629d5d6703..ee957d4da882 100644
--- a/drivers/leds/leds-lm3642.c
+++ b/drivers/leds/leds-lm3642.c
@@ -12,6 +12,7 @@
#include <linux/fs.h>
#include <linux/regmap.h>
#include <linux/platform_data/leds-lm3642.h>
+#include <linux/cleanup.h>
#define REG_FILT_TIME (0x0)
#define REG_IVFM_MODE (0x1)
@@ -202,10 +203,9 @@ static int lm3642_torch_brightness_set(struct led_classdev *cdev,
container_of(cdev, struct lm3642_chip_data, cdev_torch);
int ret;
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
chip->br_torch = brightness;
ret = lm3642_control(chip, chip->br_torch, MODES_TORCH);
- mutex_unlock(&chip->lock);
return ret;
}
@@ -249,10 +249,9 @@ static int lm3642_strobe_brightness_set(struct led_classdev *cdev,
container_of(cdev, struct lm3642_chip_data, cdev_flash);
int ret;
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
chip->br_flash = brightness;
ret = lm3642_control(chip, chip->br_flash, MODES_FLASH);
- mutex_unlock(&chip->lock);
return ret;
}
@@ -264,10 +263,9 @@ static int lm3642_indicator_brightness_set(struct led_classdev *cdev,
container_of(cdev, struct lm3642_chip_data, cdev_indicator);
int ret;
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
chip->br_indicator = brightness;
ret = lm3642_control(chip, chip->br_indicator, MODES_INDIC);
- mutex_unlock(&chip->lock);
return ret;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] leds: lm3642: use guard to simplify locking
2026-03-11 4:00 [PATCH] leds: lm3642: use guard to simplify locking Richard Lyu
@ 2026-03-19 15:15 ` Lee Jones
0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2026-03-19 15:15 UTC (permalink / raw)
To: Richard Lyu; +Cc: Pavel Machek, linux-leds, linux-kernel
[Actually Cc:ing the list this time!]
> The mutex_lock()/mutex_unlock() pattern requires explicitly pairing
> lock and unlock calls. Use guard(mutex) instead so the lock is
> automatically released when the scope exits.
>
> Convert to guard(mutex) in lm3642_torch_brightness_set(),
> lm3642_strobe_brightness_set(), and lm3642_indicator_brightness_set().
> Add #include <linux/cleanup.h> to support scoped guards.
>
> Signed-off-by: Richard Lyu <richard.lyu@suse.com>
> ---
> drivers/leds/leds-lm3642.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/leds/leds-lm3642.c b/drivers/leds/leds-lm3642.c
> index 61629d5d6703..ee957d4da882 100644
> --- a/drivers/leds/leds-lm3642.c
> +++ b/drivers/leds/leds-lm3642.c
> @@ -12,6 +12,7 @@
> #include <linux/fs.h>
> #include <linux/regmap.h>
> #include <linux/platform_data/leds-lm3642.h>
> +#include <linux/cleanup.h>
Could you please take this moment to place these in alphabetical order.
Then rebase your patch on top of it please.
> #define REG_FILT_TIME (0x0)
> #define REG_IVFM_MODE (0x1)
> @@ -202,10 +203,9 @@ static int lm3642_torch_brightness_set(struct led_classdev *cdev,
> container_of(cdev, struct lm3642_chip_data, cdev_torch);
> int ret;
>
> - mutex_lock(&chip->lock);
> + guard(mutex)(&chip->lock);
> chip->br_torch = brightness;
> ret = lm3642_control(chip, chip->br_torch, MODES_TORCH);
> - mutex_unlock(&chip->lock);
> return ret;
> }
>
> @@ -249,10 +249,9 @@ static int lm3642_strobe_brightness_set(struct led_classdev *cdev,
> container_of(cdev, struct lm3642_chip_data, cdev_flash);
> int ret;
>
> - mutex_lock(&chip->lock);
> + guard(mutex)(&chip->lock);
> chip->br_flash = brightness;
> ret = lm3642_control(chip, chip->br_flash, MODES_FLASH);
> - mutex_unlock(&chip->lock);
> return ret;
> }
>
> @@ -264,10 +263,9 @@ static int lm3642_indicator_brightness_set(struct led_classdev *cdev,
> container_of(cdev, struct lm3642_chip_data, cdev_indicator);
> int ret;
>
> - mutex_lock(&chip->lock);
> + guard(mutex)(&chip->lock);
> chip->br_indicator = brightness;
> ret = lm3642_control(chip, chip->br_indicator, MODES_INDIC);
> - mutex_unlock(&chip->lock);
> return ret;
> }
>
> --
> 2.51.0
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-19 15:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 4:00 [PATCH] leds: lm3642: use guard to simplify locking Richard Lyu
2026-03-19 15:15 ` Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox