Messages in this thread Patch in this message |  | | From | Joshua Crofts via B4 Relay <> | | Date | Tue, 05 May 2026 09:31:33 +0200 | | Subject | [PATCH v5 8/8] iio: light: si1133: use guard(mutex)() macro |
| |
From: Joshua Crofts <joshua.crofts1@gmail.com>
Remove mutex_lock()/mutex_unlock() and goto instances and add guard(mutex)() macro to modernize driver and improve mutex handling.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com> --- drivers/iio/light/si1133.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c index a3e4ab25acdc105d3800994f4391a7e4291e1c74..55660dccfc7956e77b1d8105b7261221176c1736 100644 --- a/drivers/iio/light/si1133.c +++ b/drivers/iio/light/si1133.c @@ -8,6 +8,7 @@ #include <linux/array_size.h> #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/completion.h> #include <linux/delay.h> #include <linux/dev_printk.h> @@ -396,7 +397,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd) int err; int expected_seq; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); expected_seq = (data->rsp_seq + 1) & SI1133_MAX_CMD_CTR; @@ -413,19 +414,18 @@ static int si1133_command(struct si1133_data *data, u8 cmd) if (err) { dev_warn(dev, "Failed to write command 0x%02x, ret=%d\n", cmd, err); - goto out; + return err; } if (cmd == SI1133_CMD_FORCE) { /* wait for irq */ if (!wait_for_completion_timeout(&data->completion, timeout)) { regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0); - err = -ETIMEDOUT; - goto out; + return -ETIMEDOUT; } err = regmap_read(data->regmap, SI1133_REG_RESPONSE0, &resp); if (err) - goto out; + return err; } else { err = regmap_read_poll_timeout(data->regmap, SI1133_REG_RESPONSE0, resp, @@ -443,7 +443,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd) * counters being out of sync. */ si1133_cmd_reset_counter(data); - goto out; + return err; } } @@ -454,9 +454,6 @@ static int si1133_command(struct si1133_data *data, u8 cmd) data->rsp_seq = expected_seq; } -out: - mutex_unlock(&data->mutex); - return err; } -- 2.47.3
|  |