public inbox for linux-leds@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: linux-leds@vger.kernel.org
Cc: j.anaszewski@samsung.com
Subject: [bug report] leds: ns2: Remove work queue
Date: Fri, 10 Dec 2021 16:52:49 +0300	[thread overview]
Message-ID: <20211210135249.GA16777@kili> (raw)

Hello LED devs,

The patch c29e650b3af2: "leds: ns2: Remove work queue" from Nov 20,
2015, leads to the following Smatch static checker warning:

	drivers/leds/leds-ns2.c:96 ns2_led_set_mode()
	warn: sleeping in atomic context

drivers/leds/leds-ns2.c
    76 static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
    77 {
    78         int i;
    79         unsigned long flags;
    80 
    81         for (i = 0; i < led->num_modes; i++)
    82                 if (mode == led->modval[i].mode)
    83                         break;
    84 
    85         if (i == led->num_modes)
    86                 return;
    87 
    88         write_lock_irqsave(&led->rw_lock, flags);
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Holding a write lock (spin lock).

    89 
    90         if (!led->can_sleep) {
                    ^^^^^^^^^^^^^^^
Even if the led->can_sleep flag is set, we are not actually allowed to
sleep when the preempt count is non-zero.  Presumably we should make
this unconditional.

    91                 gpiod_set_value(led->cmd, led->modval[i].cmd_level);
    92                 gpiod_set_value(led->slow, led->modval[i].slow_level);
    93                 goto exit_unlock;
    94         }
    95 
--> 96         gpiod_set_value_cansleep(led->cmd, led->modval[i].cmd_level);
    97         gpiod_set_value_cansleep(led->slow, led->modval[i].slow_level);
               ^^^^^^^^^^^^^^^^^^^^^^^^^
These functions can sleep.

    98 
    99 exit_unlock:
    100         write_unlock_irqrestore(&led->rw_lock, flags);
    101 }

regards,
dan carpenter

             reply	other threads:[~2021-12-10 13:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10 13:52 Dan Carpenter [this message]
2021-12-15 20:39 ` [bug report] leds: ns2: Remove work queue Pavel Machek
2021-12-15 21:04   ` Marek Behún
2021-12-16 10:30     ` Simon Guinot
2021-12-20 17:00     ` Ian Pilcher
2021-12-16 10:28   ` Simon Guinot

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=20211210135249.GA16777@kili \
    --to=dan.carpenter@oracle.com \
    --cc=j.anaszewski@samsung.com \
    --cc=linux-leds@vger.kernel.org \
    /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