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

gpio: latch: use lock guards

Use lock guards from linux/cleanup.h. This will make the subsequent
commit that switches to using value returning GPIO line setters much
simpler as we'll be able to return values without caring about releasing
the locks.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20250220-gpio-set-retval-v2-12-bc4cfd38dae3@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+3 -7
+3 -7
drivers/gpio/gpio-latch.c
··· 38 38 * in the corresponding device tree properties. 39 39 */ 40 40 41 + #include <linux/cleanup.h> 41 42 #include <linux/err.h> 42 43 #include <linux/gpio/consumer.h> 43 44 #include <linux/gpio/driver.h> ··· 95 94 static void gpio_latch_set(struct gpio_chip *gc, unsigned int offset, int val) 96 95 { 97 96 struct gpio_latch_priv *priv = gpiochip_get_data(gc); 98 - unsigned long flags; 99 97 100 - spin_lock_irqsave(&priv->spinlock, flags); 98 + guard(spinlock_irqsave)(&priv->spinlock); 101 99 102 100 gpio_latch_set_unlocked(priv, gpiod_set_value, offset, val); 103 - 104 - spin_unlock_irqrestore(&priv->spinlock, flags); 105 101 } 106 102 107 103 static void gpio_latch_set_can_sleep(struct gpio_chip *gc, unsigned int offset, int val) 108 104 { 109 105 struct gpio_latch_priv *priv = gpiochip_get_data(gc); 110 106 111 - mutex_lock(&priv->mutex); 107 + guard(mutex)(&priv->mutex); 112 108 113 109 gpio_latch_set_unlocked(priv, gpiod_set_value_cansleep, offset, val); 114 - 115 - mutex_unlock(&priv->mutex); 116 110 } 117 111 118 112 static bool gpio_latch_can_sleep(struct gpio_latch_priv *priv, unsigned int n_latches)