summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Lyu <richard.lyu@suse.com>2026-03-11 11:59:26 +0300
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>2026-03-16 11:52:51 +0300
commit8a3613898ff3b7eb9eed252f41aebcc1d7af4a31 (patch)
tree1e467561673cff8d2ae423745f1a1ea4ed112a8c
parent696e9ba9a3da3d919d08a1abf05c9288311858f1 (diff)
downloadlinux-8a3613898ff3b7eb9eed252f41aebcc1d7af4a31.tar.xz
gpio: max732x: use guard(mutex) to simplify locking
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>
-rw-r--r--drivers/gpio/gpio-max732x.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index a61d670ceeda..281ba1740a6a 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -10,14 +10,18 @@
* 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)