[bug report] leds: ns2: Remove work queue

Dan Carpenter
2021-12-10T13:53:06Z

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