From: Jacek Anaszewski <j.anaszewski@samsung.com>
To: Milo Kim <milo.kim@ti.com>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] leds: turn off the LED and wait for completion on unregistering LED class device
Date: Fri, 20 Nov 2015 09:59:05 +0100 [thread overview]
Message-ID: <564EE0D9.9030608@samsung.com> (raw)
In-Reply-To: <1448006580-4232-1-git-send-email-milo.kim@ti.com>
Hi Milo,
Thanks for catching this, applied.
Best Regards,
Jacek Anaszewski
On 11/20/2015 09:03 AM, Milo Kim wrote:
> Workqueue, 'set_brightness_work' is used for scheduling brightness control.
> This workqueue is canceled when the LED class device is unregistered.
> Currently, LED subsystem handles like below.
>
> cancel_work_sync(&led_cdev->set_brightness_work)
> led_set_brightness(led_cdev, LED_OFF)
>
> However, this could be a problem.
> Workqueue is going to be canceled but LED device needs to be off.
> The worst case is null pointer access due to scheduling a workqueue.
>
> LED module is loaded.
> LED driver private data is allocated by using devm_zalloc().
>
> LED module is unloaded.
> led_classdev_unregister() is called.
> cancel_work_sync()
> led_set_brightness(led_cdev, LED_OFF)
> schedule_work() if LED driver uses brightness_set_blocking()
> In the meantime, driver private data will be freed.
>
> ..scheduling..
>
> brightness_set_blocking() callback is invoked.
> For the brightness control, LED driver tries to access private
> data but resource is removed!
>
> To avoid this problem, LED subsystem should turn off the brightness first
> and wait for completion.
>
> led_set_brightness(led_cdev, LED_OFF)
> flush_work(&led_cdev->set_brightness_work)
>
> It guarantees that LED driver turns off the brightness prior to
> resource management.
>
> Cc: linux-leds@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Milo Kim <milo.kim@ti.com>
> ---
> drivers/leds/led-class.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index d946991..14139c3 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -245,12 +245,13 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
> up_write(&led_cdev->trigger_lock);
> #endif
>
> - cancel_work_sync(&led_cdev->set_brightness_work);
> -
> /* Stop blinking */
> led_stop_software_blink(led_cdev);
> +
> led_set_brightness(led_cdev, LED_OFF);
>
> + flush_work(&led_cdev->set_brightness_work);
> +
> device_unregister(led_cdev->dev);
>
> down_write(&leds_list_lock);
>
prev parent reply other threads:[~2015-11-20 8:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 8:03 [PATCH] leds: turn off the LED and wait for completion on unregistering LED class device Milo Kim
2015-11-20 8:59 ` Jacek Anaszewski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=564EE0D9.9030608@samsung.com \
--to=j.anaszewski@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=milo.kim@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox