Skip to content

Commit 6284428

Browse files
committed
Input: cap11xx - switch to using set_brightness_blocking()
Updating LED state requires access to regmap and therefore we may sleep, so we could not do that directly form set_brightness() method. Historically we used private work to adjust the brightness, but with the introduction of set_brightness_blocking() we no longer need it. As a bonus, not having our own work item means we do not have use-after-free issue as we neglected to cancel outstanding work on driver unbind. Reported-by: Sven Van Asbroeck <thesven73@gmail.com> Reviewed-by: Sven Van Asbroeck <TheSven73@googlemail.com> Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent e8b22d0 commit 6284428

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

drivers/input/keyboard/cap11xx.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@
7575
struct cap11xx_led {
7676
struct cap11xx_priv *priv;
7777
struct led_classdev cdev;
78-
struct work_struct work;
7978
u32 reg;
80-
enum led_brightness new_brightness;
8179
};
8280
#endif
8381

@@ -233,30 +231,21 @@ static void cap11xx_input_close(struct input_dev *idev)
233231
}
234232

235233
#ifdef CONFIG_LEDS_CLASS
236-
static void cap11xx_led_work(struct work_struct *work)
234+
static int cap11xx_led_set(struct led_classdev *cdev,
235+
enum led_brightness value)
237236
{
238-
struct cap11xx_led *led = container_of(work, struct cap11xx_led, work);
237+
struct cap11xx_led *led = container_of(cdev, struct cap11xx_led, cdev);
239238
struct cap11xx_priv *priv = led->priv;
240-
int value = led->new_brightness;
241239

242240
/*
243-
* All LEDs share the same duty cycle as this is a HW limitation.
244-
* Brightness levels per LED are either 0 (OFF) and 1 (ON).
241+
* All LEDs share the same duty cycle as this is a HW
242+
* limitation. Brightness levels per LED are either
243+
* 0 (OFF) and 1 (ON).
245244
*/
246-
regmap_update_bits(priv->regmap, CAP11XX_REG_LED_OUTPUT_CONTROL,
247-
BIT(led->reg), value ? BIT(led->reg) : 0);
248-
}
249-
250-
static void cap11xx_led_set(struct led_classdev *cdev,
251-
enum led_brightness value)
252-
{
253-
struct cap11xx_led *led = container_of(cdev, struct cap11xx_led, cdev);
254-
255-
if (led->new_brightness == value)
256-
return;
257-
258-
led->new_brightness = value;
259-
schedule_work(&led->work);
245+
return regmap_update_bits(priv->regmap,
246+
CAP11XX_REG_LED_OUTPUT_CONTROL,
247+
BIT(led->reg),
248+
value ? BIT(led->reg) : 0);
260249
}
261250

262251
static int cap11xx_init_leds(struct device *dev,
@@ -299,7 +288,7 @@ static int cap11xx_init_leds(struct device *dev,
299288
led->cdev.default_trigger =
300289
of_get_property(child, "linux,default-trigger", NULL);
301290
led->cdev.flags = 0;
302-
led->cdev.brightness_set = cap11xx_led_set;
291+
led->cdev.brightness_set_blocking = cap11xx_led_set;
303292
led->cdev.max_brightness = 1;
304293
led->cdev.brightness = LED_OFF;
305294

@@ -312,8 +301,6 @@ static int cap11xx_init_leds(struct device *dev,
312301
led->reg = reg;
313302
led->priv = priv;
314303

315-
INIT_WORK(&led->work, cap11xx_led_work);
316-
317304
error = devm_led_classdev_register(dev, &led->cdev);
318305
if (error) {
319306
of_node_put(child);

0 commit comments

Comments
 (0)