From: Richard Lyu <richard.lyu@suse.com>
To: Lee Jones <lee@kernel.org>
Cc: Pavel Machek <pavel@kernel.org>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
Richard Lyu <richard.lyu@suse.com>
Subject: [PATCH v2] leds: lm3642: use guard to simplify locking
Date: Fri, 20 Mar 2026 11:54:52 +0800 [thread overview]
Message-ID: <20260320035451.31071-1-richard.lyu@suse.com> (raw)
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>
---
v2:
- Sort includes alphabetically as requested by Lee Jones.
- Rebase this patch on top.
- Link: https://lore.kernel.org/all/20260319151539.GO554736@google.com/
---
drivers/leds/leds-lm3642.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/leds/leds-lm3642.c b/drivers/leds/leds-lm3642.c
index 61629d5d6703..36246267b096 100644
--- a/drivers/leds/leds-lm3642.c
+++ b/drivers/leds/leds-lm3642.c
@@ -3,15 +3,16 @@
* Simple driver for Texas Instruments LM3642 LED Flash driver chip
* Copyright (C) 2012 Texas Instruments
*/
-#include <linux/module.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
+#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/leds.h>
-#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/platform_data/leds-lm3642.h>
#include <linux/platform_device.h>
-#include <linux/fs.h>
#include <linux/regmap.h>
-#include <linux/platform_data/leds-lm3642.h>
+#include <linux/slab.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
next reply other threads:[~2026-03-20 3:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 3:54 Richard Lyu [this message]
2026-03-26 11:25 ` (subset) [PATCH v2] leds: lm3642: use guard to simplify locking Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260320035451.31071-1-richard.lyu@suse.com \
--to=richard.lyu@suse.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox