From: Richard Lyu Date: Wed, 11 Mar 2026 08:59:26 +0000 (+0800) Subject: gpio: max732x: use guard(mutex) to simplify locking X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a3613898ff3b7eb9eed252f41aebcc1d7af4a31;p=thirdparty%2Fkernel%2Flinux.git gpio: max732x: use guard(mutex) to simplify locking Convert the max732x driver to use the RAII-based guard(mutex) macro from . This change replaces manual mutex_lock() and mutex_unlock() calls, allowing the chip lock to be managed automatically based on function scope. Refactor max732x_gpio_set_mask() and max732x_irq_update_mask() to improve code readability. This allows for direct returns and removes the redundant 'out' label in the set_mask function, resulting in cleaner and more maintainable code. While at it: order includes alphabetically and add missing ones. Signed-off-by: Richard Lyu Link: https://patch.msgid.link/20260311085924.191288-1-richard.lyu@suse.com [Bartosz: tweak commit message, add err.h and device.h to includes] Signed-off-by: Bartosz Golaszewski --- diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index a61d670ceeda6..281ba1740a6a0 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c @@ -10,14 +10,18 @@ * Derived from drivers/gpio/pca953x.c */ -#include -#include -#include -#include +#include +#include +#include #include -#include #include +#include +#include +#include +#include #include +#include +#include /* * Each port of MAX732x (including MAX7319) falls into one of the @@ -207,22 +211,20 @@ static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask, uint8_t reg_out; int ret; - mutex_lock(&chip->lock); + guard(mutex)(&chip->lock); reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; reg_out = (reg_out & ~mask) | (val & mask); ret = max732x_writeb(chip, is_group_a(chip, off), reg_out); if (ret < 0) - goto out; + return; /* update the shadow register then */ if (off > 7) chip->reg_out[1] = reg_out; else chip->reg_out[0] = reg_out; -out: - mutex_unlock(&chip->lock); } static int max732x_gpio_set_value(struct gpio_chip *gc, unsigned int off, @@ -329,7 +331,7 @@ static void max732x_irq_update_mask(struct max732x_chip *chip) if (chip->irq_features == INT_NO_MASK) return; - mutex_lock(&chip->lock); + guard(mutex)(&chip->lock); switch (chip->irq_features) { case INT_INDEP_MASK: @@ -342,8 +344,6 @@ static void max732x_irq_update_mask(struct max732x_chip *chip) max732x_writeb(chip, 1, (uint8_t)msg); break; } - - mutex_unlock(&chip->lock); } static void max732x_irq_mask(struct irq_data *d)