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

Commit b420097e authored by Devesh Jhunjhunwala's avatar Devesh Jhunjhunwala Committed by Subbaraman Narayanamurthy
Browse files

leds: qpnp-flash-v2: Fix possible NULL pointer dereference



Update the flash_led_brightness_set callback to gracefully handle
invalid led_class device, and being called before driver probe is
complete.

CRs-Fixed: 1060705
Change-Id: Ice714c1fad1d202d05de6ecaf6d1d1ec17a04c15
Signed-off-by: default avatarDevesh Jhunjhunwala <deveshj@codeaurora.org>
parent 169fd1f5
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1013,17 +1013,24 @@ static void qpnp_flash_led_brightness_set(struct led_classdev *led_cdev,
{
	struct flash_node_data *fnode = NULL;
	struct flash_switch_data *snode = NULL;
	struct qpnp_flash_led *led = dev_get_drvdata(&fnode->pdev->dev);
	struct qpnp_flash_led *led = NULL;
	int rc;

	if (!strncmp(led_cdev->name, "led:switch", strlen("led:switch"))) {
		snode = container_of(led_cdev, struct flash_switch_data, cdev);
		led = dev_get_drvdata(&snode->pdev->dev);
	} else {
	} else if (!strncmp(led_cdev->name, "led:flash", strlen("led:flash")) ||
			!strncmp(led_cdev->name, "led:torch",
						strlen("led:torch"))) {
		fnode = container_of(led_cdev, struct flash_node_data, cdev);
		led = dev_get_drvdata(&fnode->pdev->dev);
	}

	if (!led) {
		pr_err("Failed to get flash driver data\n");
		return;
	}

	spin_lock(&led->lock);
	if (snode) {
		rc = qpnp_flash_led_switch_set(snode, value > 0);