Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Richard Lyu and committed by
Lee Jones
a55e941e 91dc0c2a

+9 -11
+9 -11
drivers/leds/leds-lm3642.c
··· 3 3 * Simple driver for Texas Instruments LM3642 LED Flash driver chip 4 4 * Copyright (C) 2012 Texas Instruments 5 5 */ 6 - #include <linux/module.h> 6 + #include <linux/cleanup.h> 7 7 #include <linux/delay.h> 8 + #include <linux/fs.h> 8 9 #include <linux/i2c.h> 9 10 #include <linux/leds.h> 10 - #include <linux/slab.h> 11 - #include <linux/platform_device.h> 12 - #include <linux/fs.h> 13 - #include <linux/regmap.h> 11 + #include <linux/module.h> 14 12 #include <linux/platform_data/leds-lm3642.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/regmap.h> 15 + #include <linux/slab.h> 15 16 16 17 #define REG_FILT_TIME (0x0) 17 18 #define REG_IVFM_MODE (0x1) ··· 203 202 container_of(cdev, struct lm3642_chip_data, cdev_torch); 204 203 int ret; 205 204 206 - mutex_lock(&chip->lock); 205 + guard(mutex)(&chip->lock); 207 206 chip->br_torch = brightness; 208 207 ret = lm3642_control(chip, chip->br_torch, MODES_TORCH); 209 - mutex_unlock(&chip->lock); 210 208 return ret; 211 209 } 212 210 ··· 249 249 container_of(cdev, struct lm3642_chip_data, cdev_flash); 250 250 int ret; 251 251 252 - mutex_lock(&chip->lock); 252 + guard(mutex)(&chip->lock); 253 253 chip->br_flash = brightness; 254 254 ret = lm3642_control(chip, chip->br_flash, MODES_FLASH); 255 - mutex_unlock(&chip->lock); 256 255 return ret; 257 256 } 258 257 ··· 263 264 container_of(cdev, struct lm3642_chip_data, cdev_indicator); 264 265 int ret; 265 266 266 - mutex_lock(&chip->lock); 267 + guard(mutex)(&chip->lock); 267 268 chip->br_indicator = brightness; 268 269 ret = lm3642_control(chip, chip->br_indicator, MODES_INDIC); 269 - mutex_unlock(&chip->lock); 270 270 return ret; 271 271 } 272 272