summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2019-08-28 00:52:05 +0300
committerJacek Anaszewski <jacek.anaszewski@gmail.com>2019-09-01 14:33:27 +0300
commit070a0eed7580a976b397dce981db9746df714327 (patch)
tree1f1833d75533d88e2672b999e52dfefd07509801 /drivers/leds
parent68bfcf6debd72121758d6e0fbf75f506126d7b9a (diff)
downloadlinux-070a0eed7580a976b397dce981db9746df714327.tar.xz
leds: lm3532: Avoid potentially unpaired regulator calls
We may currently get unpaired regulator calls when configuring the LED brightness via sysfs in case of regulator calls producing errors. Let's fix this by maintaining local state for enabled. Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-lm3532.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
index ba352d76a8fb..c5cfd8e3f15f 100644
--- a/drivers/leds/leds-lm3532.c
+++ b/drivers/leds/leds-lm3532.c
@@ -127,6 +127,7 @@ struct lm3532_als_data {
* @num_leds - Number of LED strings are supported in this array
* @full_scale_current - The full-scale current setting for the current sink.
* @led_strings - The LED strings supported in this array
+ * @enabled - Enabled status
* @label - LED label
*/
struct lm3532_led {
@@ -138,6 +139,7 @@ struct lm3532_led {
int ctrl_brt_pointer;
int num_leds;
int full_scale_current;
+ int enabled:1;
u32 led_strings[LM3532_MAX_CONTROL_BANKS];
char label[LED_MAX_NAME_SIZE];
};
@@ -292,11 +294,15 @@ static int lm3532_get_ramp_index(int ramp_time)
ramp_time);
}
+/* Caller must take care of locking */
static int lm3532_led_enable(struct lm3532_led *led_data)
{
int ctrl_en_val = BIT(led_data->control_bank);
int ret;
+ if (led_data->enabled)
+ return 0;
+
ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE,
ctrl_en_val, ctrl_en_val);
if (ret) {
@@ -304,14 +310,24 @@ static int lm3532_led_enable(struct lm3532_led *led_data)
return ret;
}
- return regulator_enable(led_data->priv->regulator);
+ ret = regulator_enable(led_data->priv->regulator);
+ if (ret < 0)
+ return ret;
+
+ led_data->enabled = 1;
+
+ return 0;
}
+/* Caller must take care of locking */
static int lm3532_led_disable(struct lm3532_led *led_data)
{
int ctrl_en_val = BIT(led_data->control_bank);
int ret;
+ if (!led_data->enabled)
+ return 0;
+
ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE,
ctrl_en_val, 0);
if (ret) {
@@ -319,7 +335,13 @@ static int lm3532_led_disable(struct lm3532_led *led_data)
return ret;
}
- return regulator_disable(led_data->priv->regulator);
+ ret = regulator_disable(led_data->priv->regulator);
+ if (ret < 0)
+ return ret;
+
+ led_data->enabled = 0;
+
+ return 0;
}
static int lm3532_brightness_set(struct led_classdev *led_cdev,