mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
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>
This commit is contained in:
committed by
Bartosz Golaszewski
parent
696e9ba9a3
commit
8a3613898f
@@ -10,14 +10,18 @@
|
||||
* Derived from drivers/gpio/pca953x.c
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/gpio/driver.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>
|
||||
#include <linux/gpio/driver.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/platform_data/max732x.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)
|
||||
|
||||
Reference in New Issue
Block a user