diff options
| author | Linux Build Service Account <lnxbuild@localhost> | 2017-01-18 23:48:52 -0800 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2017-01-18 23:48:52 -0800 |
| commit | f7d60162607d2cd29ade8893ec221eccf613dee3 (patch) | |
| tree | fa436e1bdb27c3cc4cc46a335ca0426e349dff11 | |
| parent | d1d4a1d606988b6863830dde6979ec5083aaa578 (diff) | |
| parent | 00d283019bf1366a5e914e83224de6c214d41c13 (diff) | |
Merge "leds: qpnp-flash-v2: fix a possible NULL pointer access"
| -rw-r--r-- | drivers/leds/led-class.c | 2 | ||||
| -rw-r--r-- | drivers/leds/leds-qpnp-flash-v2.c | 13 | ||||
| -rw-r--r-- | include/linux/leds.h | 1 |
3 files changed, 12 insertions, 4 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index d3f65fa67ebd..ba20b8e42fbd 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -53,7 +53,7 @@ static ssize_t brightness_store(struct device *dev, if (ret) goto unlock; - if (state == LED_OFF) + if (state == LED_OFF && !(led_cdev->flags & LED_KEEP_TRIGGER)) led_trigger_remove(led_cdev); led_set_brightness(led_cdev, state); led_cdev->usr_brightness_req = state; diff --git a/drivers/leds/leds-qpnp-flash-v2.c b/drivers/leds/leds-qpnp-flash-v2.c index aa59677c4b6a..b6aa4a87f31d 100644 --- a/drivers/leds/leds-qpnp-flash-v2.c +++ b/drivers/leds/leds-qpnp-flash-v2.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -1102,16 +1102,22 @@ static int qpnp_flash_led_switch_set(struct flash_switch_data *snode, bool on) int qpnp_flash_led_prepare(struct led_trigger *trig, int options, int *max_current) { - struct led_classdev *led_cdev = trigger_to_lcdev(trig); + struct led_classdev *led_cdev; struct flash_switch_data *snode; struct qpnp_flash_led *led; int rc; - if (!led_cdev) { + if (!trig) { pr_err("Invalid led_trigger provided\n"); return -EINVAL; } + led_cdev = trigger_to_lcdev(trig); + if (!led_cdev) { + pr_err("Invalid led_cdev in trigger %s\n", trig->name); + return -EINVAL; + } + snode = container_of(led_cdev, struct flash_switch_data, cdev); led = dev_get_drvdata(&snode->pdev->dev); @@ -1569,6 +1575,7 @@ static int qpnp_flash_led_parse_and_register_switch(struct qpnp_flash_led *led, snode->pdev = led->pdev; snode->cdev.brightness_set = qpnp_flash_led_brightness_set; snode->cdev.brightness_get = qpnp_flash_led_brightness_get; + snode->cdev.flags |= LED_KEEP_TRIGGER; rc = led_classdev_register(&led->pdev->dev, &snode->cdev); if (rc < 0) { pr_err("Unable to register led switch node\n"); diff --git a/include/linux/leds.h b/include/linux/leds.h index bba189a62dfd..197b61500ab7 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -49,6 +49,7 @@ struct led_classdev { #define SET_BRIGHTNESS_ASYNC (1 << 21) #define SET_BRIGHTNESS_SYNC (1 << 22) #define LED_DEV_CAP_FLASH (1 << 23) +#define LED_KEEP_TRIGGER (1 << 24) /* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */ |
