summaryrefslogtreecommitdiff
path: root/drivers/leds/leds-lp5569.c
diff options
context:
space:
mode:
authorChristian Marangi <ansuelsmth@gmail.com>2024-06-27 00:15:13 +0200
committerLee Jones <lee@kernel.org>2024-07-11 12:46:25 +0100
commit4137d94fd8726431b8bf3ab329311c59e80f5530 (patch)
treec19379bcf34e9b3cee2a13d32dcad1e098a84ec4 /drivers/leds/leds-lp5569.c
parent8eac0379d3bd9d048b1144d74d9309a198fd3f40 (diff)
leds: leds-lp55xx: Convert mutex lock/unlock to guard API
Convert any entry of mutex lock/unlock to guard API and simplify code. With the use of guard API, handling for selttest functions can be greatly simplified. Suggested-by: Markus Elfring <Markus.Elfring@web.de> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Link: https://lore.kernel.org/r/20240626221520.2846-3-ansuelsmth@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds/leds-lp5569.c')
-rw-r--r--drivers/leds/leds-lp5569.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c
index e5e7e61c8916..377f2c100bc2 100644
--- a/drivers/leds/leds-lp5569.c
+++ b/drivers/leds/leds-lp5569.c
@@ -4,6 +4,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
@@ -396,17 +397,17 @@ static ssize_t lp5569_selftest(struct device *dev,
struct lp55xx_chip *chip = led->chip;
int i, pos = 0;
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
/* Test LED Open */
pos = lp5569_led_open_test(led, buf);
if (pos < 0)
- goto fail;
+ return sprintf(buf, "FAIL\n");
/* Test LED Shorted */
pos += lp5569_led_short_test(led, buf);
if (pos < 0)
- goto fail;
+ return sprintf(buf, "FAIL\n");
for (i = 0; i < chip->pdata->num_channels; i++) {
/* Restore current */
@@ -419,16 +420,7 @@ static ssize_t lp5569_selftest(struct device *dev,
led++;
}
- if (pos == 0)
- pos = sysfs_emit(buf, "OK\n");
- goto release_lock;
-fail:
- pos = sysfs_emit(buf, "FAIL\n");
-
-release_lock:
- mutex_unlock(&chip->lock);
-
- return pos;
+ return pos == 0 ? sysfs_emit(buf, "OK\n") : pos;
}
LP55XX_DEV_ATTR_ENGINE_MODE(1);