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

Commit 01c99613 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

leds: qpnp-flash-v2: Fix some issues



An out of bounds access is attempted to calculate code for
iclamp_low_ma and iclamp_mid_ma for LED3. Use the right index in
flash_node pointer to fix it.

When an error is found during probe especially before registering
a flash LED class device, unregistering flash LED class devices
is made on a flash LED class device that is not registered yet.
Fix it.

Change-Id: I2f6650eb24ecbece473abfe18a9a2e26c62c1253
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent b0201565
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -509,7 +509,7 @@ static int qpnp_flash_led_init_settings(struct qpnp_flash_led *led)

	if (led->pdata->led1n2_iclamp_low_ma) {
		val = CURRENT_MA_TO_REG_VAL(led->pdata->led1n2_iclamp_low_ma,
						led->fnode[0].ires_ua);
						led->fnode[LED1].ires_ua);
		rc = qpnp_flash_led_masked_write(led,
				FLASH_LED_REG_LED1N2_ICLAMP_LOW(led->base),
				FLASH_LED_CURRENT_MASK, val);
@@ -519,7 +519,7 @@ static int qpnp_flash_led_init_settings(struct qpnp_flash_led *led)

	if (led->pdata->led1n2_iclamp_mid_ma) {
		val = CURRENT_MA_TO_REG_VAL(led->pdata->led1n2_iclamp_mid_ma,
						led->fnode[0].ires_ua);
						led->fnode[LED1].ires_ua);
		rc = qpnp_flash_led_masked_write(led,
				FLASH_LED_REG_LED1N2_ICLAMP_MID(led->base),
				FLASH_LED_CURRENT_MASK, val);
@@ -529,7 +529,7 @@ static int qpnp_flash_led_init_settings(struct qpnp_flash_led *led)

	if (led->pdata->led3_iclamp_low_ma) {
		val = CURRENT_MA_TO_REG_VAL(led->pdata->led3_iclamp_low_ma,
						led->fnode[3].ires_ua);
						led->fnode[LED3].ires_ua);
		rc = qpnp_flash_led_masked_write(led,
				FLASH_LED_REG_LED3_ICLAMP_LOW(led->base),
				FLASH_LED_CURRENT_MASK, val);
@@ -539,7 +539,7 @@ static int qpnp_flash_led_init_settings(struct qpnp_flash_led *led)

	if (led->pdata->led3_iclamp_mid_ma) {
		val = CURRENT_MA_TO_REG_VAL(led->pdata->led3_iclamp_mid_ma,
						led->fnode[3].ires_ua);
						led->fnode[LED3].ires_ua);
		rc = qpnp_flash_led_masked_write(led,
				FLASH_LED_REG_LED3_ICLAMP_MID(led->base),
				FLASH_LED_CURRENT_MASK, val);
@@ -2095,22 +2095,24 @@ static int qpnp_flash_led_probe(struct platform_device *pdev)
		if (!strcmp("flash", temp_string) ||
				!strcmp("torch", temp_string)) {
			rc = qpnp_flash_led_parse_each_led_dt(led,
					&led->fnode[i++], temp);
					&led->fnode[i], temp);
			if (rc < 0) {
				pr_err("Unable to parse flash node %d rc=%d\n",
					i, rc);
				goto error_led_register;
			}
			i++;
		}

		if (!strcmp("switch", temp_string)) {
			rc = qpnp_flash_led_parse_and_register_switch(led,
					&led->snode[j++], temp);
					&led->snode[j], temp);
			if (rc < 0) {
				pr_err("Unable to parse and register switch node, rc=%d\n",
					rc);
				goto error_switch_register;
			}
			j++;
		}
	}