OSDN Git Service

leds: qpnp-flash-v2: Fix some issues
authorSubbaraman Narayanamurthy <subbaram@codeaurora.org>
Mon, 3 Apr 2017 19:26:06 +0000 (12:26 -0700)
committerSubbaraman Narayanamurthy <subbaram@codeaurora.org>
Mon, 3 Apr 2017 20:06:25 +0000 (13:06 -0700)
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: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
drivers/leds/leds-qpnp-flash-v2.c

index 54d395d..a8bf5b4 100644 (file)
@@ -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);
@@ -2094,22 +2094,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++;
                }
        }