Skip to content

Commit a55e941

Browse files
r1chard-lyulag-linaro
authored andcommitted
leds: lm3642: Use guard to simplify locking
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> Link: https://patch.msgid.link/20260320035451.31071-1-richard.lyu@suse.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 91dc0c2 commit a55e941

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

drivers/leds/leds-lm3642.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
* Simple driver for Texas Instruments LM3642 LED Flash driver chip
44
* Copyright (C) 2012 Texas Instruments
55
*/
6-
#include <linux/module.h>
6+
#include <linux/cleanup.h>
77
#include <linux/delay.h>
8+
#include <linux/fs.h>
89
#include <linux/i2c.h>
910
#include <linux/leds.h>
10-
#include <linux/slab.h>
11+
#include <linux/module.h>
12+
#include <linux/platform_data/leds-lm3642.h>
1113
#include <linux/platform_device.h>
12-
#include <linux/fs.h>
1314
#include <linux/regmap.h>
14-
#include <linux/platform_data/leds-lm3642.h>
15+
#include <linux/slab.h>
1516

1617
#define REG_FILT_TIME (0x0)
1718
#define REG_IVFM_MODE (0x1)
@@ -202,10 +203,9 @@ static int lm3642_torch_brightness_set(struct led_classdev *cdev,
202203
container_of(cdev, struct lm3642_chip_data, cdev_torch);
203204
int ret;
204205

205-
mutex_lock(&chip->lock);
206+
guard(mutex)(&chip->lock);
206207
chip->br_torch = brightness;
207208
ret = lm3642_control(chip, chip->br_torch, MODES_TORCH);
208-
mutex_unlock(&chip->lock);
209209
return ret;
210210
}
211211

@@ -249,10 +249,9 @@ static int lm3642_strobe_brightness_set(struct led_classdev *cdev,
249249
container_of(cdev, struct lm3642_chip_data, cdev_flash);
250250
int ret;
251251

252-
mutex_lock(&chip->lock);
252+
guard(mutex)(&chip->lock);
253253
chip->br_flash = brightness;
254254
ret = lm3642_control(chip, chip->br_flash, MODES_FLASH);
255-
mutex_unlock(&chip->lock);
256255
return ret;
257256
}
258257

@@ -264,10 +263,9 @@ static int lm3642_indicator_brightness_set(struct led_classdev *cdev,
264263
container_of(cdev, struct lm3642_chip_data, cdev_indicator);
265264
int ret;
266265

267-
mutex_lock(&chip->lock);
266+
guard(mutex)(&chip->lock);
268267
chip->br_indicator = brightness;
269268
ret = lm3642_control(chip, chip->br_indicator, MODES_INDIC);
270-
mutex_unlock(&chip->lock);
271269
return ret;
272270
}
273271

0 commit comments

Comments
 (0)