Skip to content

Commit

Permalink
leds: lp5521/5523: Remove duplicate mutex
Browse files Browse the repository at this point in the history
It can be a problem when a pattern is loaded via the firmware interface.
LP55xx common driver has already locked the mutex in 'lp55xx_firmware_loaded()'.
So it should be deleted.

On the other hand, locks are required in store_engine_load()
on updating program memory.

Reported-by: Pali Rohár <[email protected]>
Reported-by: Pavel Machek <[email protected]>
Signed-off-by: Milo Kim <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
Cc: <[email protected]>
  • Loading branch information
Milo Kim authored and cooloney committed Jan 10, 2014
1 parent 802eee9 commit e70988d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
12 changes: 4 additions & 8 deletions drivers/leds/leds-lp5521.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,12 @@ static int lp5521_update_program_memory(struct lp55xx_chip *chip,
if (i % 2)
goto err;

mutex_lock(&chip->lock);

for (i = 0; i < LP5521_PROGRAM_LENGTH; i++) {
ret = lp55xx_write(chip, addr[idx] + i, pattern[i]);
if (ret) {
mutex_unlock(&chip->lock);
if (ret)
return -EINVAL;
}
}

mutex_unlock(&chip->lock);

return size;

err:
Expand Down Expand Up @@ -427,15 +421,17 @@ static ssize_t store_engine_load(struct device *dev,
{
struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
struct lp55xx_chip *chip = led->chip;
int ret;

mutex_lock(&chip->lock);

chip->engine_idx = nr;
lp5521_load_engine(chip);
ret = lp5521_update_program_memory(chip, buf, len);

mutex_unlock(&chip->lock);

return lp5521_update_program_memory(chip, buf, len);
return ret;
}
store_load(1)
store_load(2)
Expand Down
12 changes: 4 additions & 8 deletions drivers/leds/leds-lp5523.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,12 @@ static int lp5523_update_program_memory(struct lp55xx_chip *chip,
if (i % 2)
goto err;

mutex_lock(&chip->lock);

for (i = 0; i < LP5523_PROGRAM_LENGTH; i++) {
ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + i, pattern[i]);
if (ret) {
mutex_unlock(&chip->lock);
if (ret)
return -EINVAL;
}
}

mutex_unlock(&chip->lock);

return size;

err:
Expand Down Expand Up @@ -548,15 +542,17 @@ static ssize_t store_engine_load(struct device *dev,
{
struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
struct lp55xx_chip *chip = led->chip;
int ret;

mutex_lock(&chip->lock);

chip->engine_idx = nr;
lp5523_load_engine_and_select_page(chip);
ret = lp5523_update_program_memory(chip, buf, len);

mutex_unlock(&chip->lock);

return lp5523_update_program_memory(chip, buf, len);
return ret;
}
store_load(1)
store_load(2)
Expand Down

0 comments on commit e70988d

Please sign in to comment.