auxdisplay: charlcd: cancel backlight work on registration failure
Subsystems (2)
PATCH v3 1/1 auxdisplay: charlcd: cancel backlight work on registration failure
With CONFIG_CHARLCD_BL_FLASH, charlcd_init() schedules bl_work before charlcd_register() calls misc_register(). If registration fails, the caller frees the charlcd object while delayed work still contains its address.
Add charlcd_deinit() to cancel the delayed work and turn the backlight off. Use it for both registration rollback and normal unregistration.
---
Changes in v3:
- Add Cc: [email protected] (Miguel).
Changes in v2:
- Factor the backlight cleanup into charlcd_deinit() and reuse it from charlcd_unregister() (Andy, Geert).
- Add the Fixes tag (Andy).
drivers/auxdisplay/charlcd.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/auxdisplay/charlcd.c +14 -7
@@ -595,6 +595,16 @@ static int charlcd_init(struct charlcd *lcd)return 0 ; } +static void charlcd_deinit (struct charlcd *lcd) +{ +struct charlcd_priv *priv =charlcd_to_priv (lcd); + +if (lcd->ops->backlight) { +cancel_delayed_work_sync (&priv->bl_work); + lcd->ops->backlight (lcd,CHARLCD_OFF ); + } +} +struct charlcd *charlcd_alloc (unsigned int drvdata_size) {struct charlcd_priv *priv;
@@ -654,8 +664,10 @@ int charlcd_register(struct charlcd *lcd)return ret; ret =misc_register (&charlcd_dev); -if (ret) +if (ret) { +charlcd_deinit (lcd);return ret; + } the_charlcd = lcd;register_reboot_notifier (&panel_notifier);
@@ -665,16 +677,11 @@ EXPORT_SYMBOL_GPL(charlcd_register);int charlcd_unregister (struct charlcd *lcd) { -struct charlcd_priv *priv =charlcd_to_priv (lcd); -unregister_reboot_notifier (&panel_notifier);charlcd_puts (lcd,"\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-" );misc_deregister (&charlcd_dev); the_charlcd =NULL ; -if (lcd->ops->backlight) { -cancel_delayed_work_sync (&priv->bl_work); - priv->lcd.ops->backlight (&priv->lcd,CHARLCD_OFF ); - } +charlcd_deinit (lcd);return 0 ; }
Signature · 1 line
2.50.1.windows.1
Quoted 3 lines · Hongyan Xu
Changes in v3:
- Add Cc: [email protected] (Miguel).
Thanks! (Usually it is not needed to send a new version just to add a tag -- it can be added by maintainers on apply)
Cheers,
Miguel
Quoted 12 lines · Hongyan Xu
With
CONFIG_CHARLCD_BL_FLASH,charlcd_init()schedulesbl_workbeforecharlcd_register()callsmisc_register(). If registration fails, the caller frees the charlcd object while delayed work still contains its address.Add
charlcd_deinit()to cancel the delayed work and turn the backlight off. Use it for both registration rollback and normal unregistration.Fixes 39f8ea46724e ("auxdisplay: charlcd: Extract character LCD core from misc/panel")Reviewed-by Geert Uytterhoeven <[email protected]>Signed-off-by Hongyan Xu <[email protected]>
Quoted 8 lines
---
Changes in v3:
- Add Cc: [email protected] (Miguel).Changes in v2:
- Factor the backlight cleanup intocharlcd_deinit()and reuse it fromcharlcd_unregister()(Andy, Geert).
- Add the Fixes tag (Andy).
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 7 lines · Hongyan Xu
With
CONFIG_CHARLCD_BL_FLASH,charlcd_init()schedulesbl_workbeforecharlcd_register()callsmisc_register(). If registration fails, the caller frees the charlcd object while delayed work still contains its address.Add
charlcd_deinit()to cancel the delayed work and turn the backlight off. Use it for both registration rollback and normal unregistration.
Pushed to my review and testing queue, thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko