mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-02-19 05:32:22 -05:00
Input: adp5589-keys - use guard notation when acquiring mutex
This makes the code more compact and error handling more robust by ensuring that mutexes are released in all code paths when control leaves critical section. Link: https://lore.kernel.org/r/20240825051627.2848495-2-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
@@ -404,7 +404,7 @@ static void adp5589_gpio_set_value(struct gpio_chip *chip,
|
||||
unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
|
||||
unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
|
||||
|
||||
mutex_lock(&kpad->gpio_lock);
|
||||
guard(mutex)(&kpad->gpio_lock);
|
||||
|
||||
if (val)
|
||||
kpad->dat_out[bank] |= bit;
|
||||
@@ -413,8 +413,6 @@ static void adp5589_gpio_set_value(struct gpio_chip *chip,
|
||||
|
||||
adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) +
|
||||
bank, kpad->dat_out[bank]);
|
||||
|
||||
mutex_unlock(&kpad->gpio_lock);
|
||||
}
|
||||
|
||||
static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off)
|
||||
@@ -422,18 +420,13 @@ static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off)
|
||||
struct adp5589_kpad *kpad = gpiochip_get_data(chip);
|
||||
unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
|
||||
unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
|
||||
int ret;
|
||||
|
||||
mutex_lock(&kpad->gpio_lock);
|
||||
guard(mutex)(&kpad->gpio_lock);
|
||||
|
||||
kpad->dir[bank] &= ~bit;
|
||||
ret = adp5589_write(kpad->client,
|
||||
kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
|
||||
kpad->dir[bank]);
|
||||
|
||||
mutex_unlock(&kpad->gpio_lock);
|
||||
|
||||
return ret;
|
||||
return adp5589_write(kpad->client,
|
||||
kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
|
||||
kpad->dir[bank]);
|
||||
}
|
||||
|
||||
static int adp5589_gpio_direction_output(struct gpio_chip *chip,
|
||||
@@ -442,9 +435,9 @@ static int adp5589_gpio_direction_output(struct gpio_chip *chip,
|
||||
struct adp5589_kpad *kpad = gpiochip_get_data(chip);
|
||||
unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
|
||||
unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
|
||||
int ret;
|
||||
int error;
|
||||
|
||||
mutex_lock(&kpad->gpio_lock);
|
||||
guard(mutex)(&kpad->gpio_lock);
|
||||
|
||||
kpad->dir[bank] |= bit;
|
||||
|
||||
@@ -453,15 +446,19 @@ static int adp5589_gpio_direction_output(struct gpio_chip *chip,
|
||||
else
|
||||
kpad->dat_out[bank] &= ~bit;
|
||||
|
||||
ret = adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A)
|
||||
+ bank, kpad->dat_out[bank]);
|
||||
ret |= adp5589_write(kpad->client,
|
||||
kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
|
||||
kpad->dir[bank]);
|
||||
error = adp5589_write(kpad->client,
|
||||
kpad->var->reg(ADP5589_GPO_DATA_OUT_A) + bank,
|
||||
kpad->dat_out[bank]);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
mutex_unlock(&kpad->gpio_lock);
|
||||
error = adp5589_write(kpad->client,
|
||||
kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
|
||||
kpad->dir[bank]);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
|
||||
|
||||
Reference in New Issue
Block a user