]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
leds: lp8860: Hold lock for all of EEPROM programming
authorAndrew Davis <afd@ti.com>
Thu, 5 Mar 2026 20:37:04 +0000 (14:37 -0600)
committerLee Jones <lee@kernel.org>
Tue, 10 Mar 2026 09:23:10 +0000 (09:23 +0000)
The lock is taken while unlocking the EEPROM but then released, it should
instead be held for the whole EEPROM programming process. To do this
merge in the lp8860_unlock_eeprom() function to the only call site in
the lp8860_init() function. This way we hold the lock for all steps.
While here, rename this function to lp8860_program_eeprom() to better
represent what it really does.

Signed-off-by: Andrew Davis <afd@ti.com>
Link: https://patch.msgid.link/20260305203706.841384-3-afd@ti.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/leds-lp8860.c

index 71dcd55f0808f2c52e7c323137ceee15a48025f5..16129ae94d65fc0b6f0469a0d199df9805d6ff90 100644 (file)
@@ -125,32 +125,6 @@ static const struct reg_sequence lp8860_eeprom_disp_regs[] = {
        { LP8860_EEPROM_REG_24, 0x3E },
 };
 
-static int lp8860_unlock_eeprom(struct lp8860_led *led)
-{
-       int ret;
-
-       guard(mutex)(&led->lock);
-
-       ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_1);
-       if (ret) {
-               dev_err(&led->client->dev, "EEPROM Unlock failed\n");
-               return ret;
-       }
-
-       ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_2);
-       if (ret) {
-               dev_err(&led->client->dev, "EEPROM Unlock failed\n");
-               return ret;
-       }
-       ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_3);
-       if (ret) {
-               dev_err(&led->client->dev, "EEPROM Unlock failed\n");
-               return ret;
-       }
-
-       return ret;
-}
-
 static int lp8860_fault_check(struct lp8860_led *led)
 {
        int ret, fault;
@@ -209,11 +183,13 @@ static int lp8860_brightness_set(struct led_classdev *led_cdev,
        return 0;
 }
 
-static int lp8860_init(struct lp8860_led *led)
+static int lp8860_program_eeprom(struct lp8860_led *led)
 {
        unsigned int read_buf;
        int ret, reg_count;
 
+       guard(mutex)(&led->lock);
+
        ret = lp8860_fault_check(led);
        if (ret)
                return ret;
@@ -222,9 +198,20 @@ static int lp8860_init(struct lp8860_led *led)
        if (ret)
                return ret;
 
-       ret = lp8860_unlock_eeprom(led);
+       ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_1);
+       if (ret) {
+               dev_err(&led->client->dev, "EEPROM Unlock failed\n");
+               return ret;
+       }
+
+       ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_2);
+       if (ret) {
+               dev_err(&led->client->dev, "EEPROM Unlock failed\n");
+               return ret;
+       }
+       ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_3);
        if (ret) {
-               dev_err(&led->client->dev, "Failed unlocking EEPROM\n");
+               dev_err(&led->client->dev, "EEPROM Unlock failed\n");
                return ret;
        }
 
@@ -318,7 +305,7 @@ static int lp8860_probe(struct i2c_client *client)
                return ret;
        }
 
-       ret = lp8860_init(led);
+       ret = lp8860_program_eeprom(led);
        if (ret)
                return ret;