Skip to content

Commit d0b396c

Browse files
cjd8jic23
authored andcommitted
iio: light: si1133: use guard(mutex)() macro
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> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 8210887 commit d0b396c

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

drivers/iio/light/si1133.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/array_size.h>
1010
#include <linux/bitops.h>
11+
#include <linux/cleanup.h>
1112
#include <linux/completion.h>
1213
#include <linux/delay.h>
1314
#include <linux/dev_printk.h>
@@ -396,7 +397,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
396397
int err;
397398
int expected_seq;
398399

399-
mutex_lock(&data->mutex);
400+
guard(mutex)(&data->mutex);
400401

401402
expected_seq = (data->rsp_seq + 1) & SI1133_MAX_CMD_CTR;
402403

@@ -413,20 +414,19 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
413414
if (err) {
414415
dev_warn(dev, "Failed to write command 0x%02x, ret=%d\n", cmd,
415416
err);
416-
goto out;
417+
return err;
417418
}
418419

419420
if (cmd == SI1133_CMD_FORCE) {
420421
/* wait for irq */
421422
timeout = msecs_to_jiffies(SI1133_COMPLETION_TIMEOUT_MS);
422423
if (!wait_for_completion_timeout(&data->completion, timeout)) {
423424
regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0);
424-
err = -ETIMEDOUT;
425-
goto out;
425+
return -ETIMEDOUT;
426426
}
427427
err = regmap_read(data->regmap, SI1133_REG_RESPONSE0, &resp);
428428
if (err)
429-
goto out;
429+
return err;
430430
} else {
431431
err = regmap_read_poll_timeout(data->regmap,
432432
SI1133_REG_RESPONSE0, resp,
@@ -444,7 +444,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
444444
* counters being out of sync.
445445
*/
446446
si1133_cmd_reset_counter(data);
447-
goto out;
447+
return err;
448448
}
449449
}
450450

@@ -455,9 +455,6 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
455455
data->rsp_seq = expected_seq;
456456
}
457457

458-
out:
459-
mutex_unlock(&data->mutex);
460-
461458
return err;
462459
}
463460

0 commit comments

Comments
 (0)