Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3bcc96d authored by Abinaya P's avatar Abinaya P
Browse files

leds: leds-qpnp: use a single global mutex for flash led



Add a single global mutex for all instances of flash leds -
flash_0,flash_1 and flash_torch to avoid concurrency issues.

CRs-Fixed: 640712
Change-Id: I38a30432a86e47e11f975358c71557da1f58667e
Signed-off-by: default avatarAbinaya P <abinayap@codeaurora.org>
parent eb7b84f4
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -548,6 +548,7 @@ struct qpnp_led_data {
};

static int num_kpbl_leds_on;
static DEFINE_MUTEX(flash_lock);

static int
qpnp_led_masked_write(struct qpnp_led_data *led, u16 addr, u8 mask, u8 val)
@@ -1706,6 +1707,9 @@ static void __qpnp_led_work(struct qpnp_led_data *led,
{
	int rc;

	if (led->id == QPNP_ID_FLASH1_LED0 || led->id == QPNP_ID_FLASH1_LED1)
		mutex_lock(&flash_lock);
	else
		mutex_lock(&led->lock);

	switch (led->id) {
@@ -1753,6 +1757,9 @@ static void __qpnp_led_work(struct qpnp_led_data *led,
		dev_err(&led->spmi_dev->dev, "Invalid LED(%d)\n", led->id);
		break;
	}
	if (led->id == QPNP_ID_FLASH1_LED0 || led->id == QPNP_ID_FLASH1_LED1)
		mutex_unlock(&flash_lock);
	else
		mutex_unlock(&led->lock);

}
@@ -3784,6 +3791,8 @@ static int qpnp_leds_probe(struct spmi_device *spmi)
			goto fail_id_check;
		}

		if (led->id != QPNP_ID_FLASH1_LED0 &&
					led->id != QPNP_ID_FLASH1_LED1)
			mutex_init(&led->lock);
		INIT_WORK(&led->work, qpnp_led_work);

@@ -3879,6 +3888,8 @@ static int qpnp_leds_probe(struct spmi_device *spmi)

fail_id_check:
	for (i = 0; i < parsed_leds; i++) {
		if (led_array[i].id != QPNP_ID_FLASH1_LED0 &&
				led_array[i].id != QPNP_ID_FLASH1_LED1)
			mutex_destroy(&led_array[i].lock);
		led_classdev_unregister(&led_array[i].cdev);
	}
@@ -3893,7 +3904,12 @@ static int qpnp_leds_remove(struct spmi_device *spmi)

	for (i = 0; i < parsed_leds; i++) {
		cancel_work_sync(&led_array[i].work);
		if (led_array[i].id != QPNP_ID_FLASH1_LED0 &&
				led_array[i].id != QPNP_ID_FLASH1_LED1)
			mutex_destroy(&led_array[i].lock);
		else if (led_array[i].id == QPNP_ID_FLASH1_LED0)
			mutex_destroy(&flash_lock);

		led_classdev_unregister(&led_array[i].cdev);
		switch (led_array[i].id) {
		case QPNP_ID_WLED: