]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: max732x: use guard(mutex) to simplify locking
authorRichard Lyu <richard.lyu@suse.com>
Wed, 11 Mar 2026 08:59:26 +0000 (16:59 +0800)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Mon, 16 Mar 2026 08:52:51 +0000 (09:52 +0100)
Convert the max732x driver to use the RAII-based guard(mutex) macro from
<linux/cleanup.h>. 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 <richard.lyu@suse.com>
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 <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpio-max732x.c

index a61d670ceeda634ccc088bbba64a0da5f451cf52..281ba1740a6a032f912e944539509f8c065a4e35 100644 (file)
  *  Derived from drivers/gpio/pca953x.c
  */
 
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/string.h>
+#include <linux/cleanup.h>
+#include <linux/err.h>
+#include <linux/device.h>
 #include <linux/gpio/driver.h>
-#include <linux/interrupt.h>
 #include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/platform_data/max732x.h>
+#include <linux/slab.h>
+#include <linux/string.h>
 
 /*
  * 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)