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

Commit 51e846ca authored by Abinaya P's avatar Abinaya P Committed by Gerrit - the friendly Code Review server
Browse files

drivers: leds-qpnp-flash: fix issues raised by static analyser



Fix the below mentioned issues raised by static analyser:
1. use of uninitialized values in the function.

a) 'root' may be uninitialized when it reaches line:2599. Hence,
modify the error path accordingly.
b) 'j' may be uninitialized when it reaches the for loop in line:
2593 and may hold garbage value due to which the condition in the
for loop may become true and this may lead to erroneous results.
Hence, initialize it to -1 so that the error path will be handled
correctly.

2. Comparison of unsigned value against 0 is always false.

Change-Id: I56950779d221acf3572cba70a64874299f127004
Signed-off-by: default avatarAbinaya P <abinayap@codeaurora.org>
parent 0940fb6a
Loading
Loading
Loading
Loading
+9 −24
Original line number Diff line number Diff line
@@ -823,7 +823,7 @@ static struct device_attribute qpnp_flash_led_attrs[] = {
				qpnp_flash_led_die_temp_store),
};

static int qpnp_flash_led_get_thermal_derate_rate(const char *rate)
static u32 qpnp_flash_led_get_thermal_derate_rate(const char *rate)
{
	/*
	 * return 5% derate as default value if user specifies
@@ -843,7 +843,7 @@ static int qpnp_flash_led_get_thermal_derate_rate(const char *rate)
		return RATE_5_PERCENT;
}

static int qpnp_flash_led_get_ramp_step(const char *step)
static u32 qpnp_flash_led_get_ramp_step(const char *step)
{
	/*
	 * return 27 us as default value if user specifies
@@ -2164,12 +2164,6 @@ static int qpnp_flash_led_parse_common_dt(
		if (!rc) {
			temp_val =
				qpnp_flash_led_get_thermal_derate_rate(temp);
			if (temp_val < 0) {
				dev_err(&led->spmi_dev->dev,
					"Invalid thermal derate rate\n");
				return -EINVAL;
			}

			led->pdata->thermal_derate_rate = (u8)temp_val;
		} else {
			dev_err(&led->spmi_dev->dev,
@@ -2198,11 +2192,6 @@ static int qpnp_flash_led_parse_common_dt(
		rc = of_property_read_string(node, "qcom,ramp_up_step", &temp);
		if (!rc) {
			temp_val = qpnp_flash_led_get_ramp_step(temp);
			if (temp_val < 0) {
				dev_err(&led->spmi_dev->dev,
					"Invalid ramp up step values\n");
				return -EINVAL;
			}
			led->pdata->ramp_up_step = (u8)temp_val;
		} else if (rc != -EINVAL) {
			dev_err(&led->spmi_dev->dev,
@@ -2214,11 +2203,6 @@ static int qpnp_flash_led_parse_common_dt(
		rc = of_property_read_string(node, "qcom,ramp_dn_step", &temp);
		if (!rc) {
			temp_val = qpnp_flash_led_get_ramp_step(temp);
			if (temp_val < 0) {
				dev_err(&led->spmi_dev->dev,
					"Invalid ramp down step values\n");
				return rc;
			}
			led->pdata->ramp_dn_step = (u8)temp_val;
		} else if (rc != -EINVAL) {
			dev_err(&led->spmi_dev->dev,
@@ -2420,12 +2404,12 @@ static int qpnp_flash_led_probe(struct spmi_device *spmi)
		return -ENOMEM;
	}

	led->peripheral_type =
			(u8)qpnp_flash_led_get_peripheral_type(led);
	if (led->peripheral_type < 0) {
	rc = qpnp_flash_led_get_peripheral_type(led);
	if (rc < 0) {
		dev_err(&spmi->dev, "Failed to get peripheral type\n");
		return rc;
	}
	led->peripheral_type = (u8) rc;

	rc = qpnp_flash_led_parse_common_dt(led, node);
	if (rc) {
@@ -2469,6 +2453,7 @@ static int qpnp_flash_led_probe(struct spmi_device *spmi)
	}

	for_each_child_of_node(node, temp) {
		j = -1;
		led->flash_node[i].cdev.brightness_set =
						qpnp_flash_led_brightness_set;
		led->flash_node[i].cdev.brightness_get =
@@ -2544,7 +2529,6 @@ static int qpnp_flash_led_probe(struct spmi_device *spmi)
			if (rc)
				goto error_led_register;
		}

		i++;
	}

@@ -2556,7 +2540,7 @@ static int qpnp_flash_led_probe(struct spmi_device *spmi)
			(long)root);
		if (PTR_ERR(root) == -ENODEV)
			pr_err("debugfs is not enabled in kernel");
		goto error_led_debugfs;
		goto error_free_led_sysfs;
	}

	led->dbgfs_root = root;
@@ -2586,6 +2570,8 @@ static int qpnp_flash_led_probe(struct spmi_device *spmi)
	return 0;

error_led_debugfs:
	debugfs_remove_recursive(root);
error_free_led_sysfs:
	i = led->num_leds - 1;
	j = ARRAY_SIZE(qpnp_flash_led_attrs) - 1;
error_led_register:
@@ -2596,7 +2582,6 @@ error_led_register:
		j = ARRAY_SIZE(qpnp_flash_led_attrs) - 1;
		led_classdev_unregister(&led->flash_node[i].cdev);
	}
	debugfs_remove_recursive(root);
	mutex_destroy(&led->flash_led_lock);
	destroy_workqueue(led->ordered_workq);