auxdisplay: hd44780: Fix memory leak on ->remove()
Subsystems (2)
PATCH 2/4 auxdisplay: charlcd: Introduce charlcd_free() helper
In reply to Andy ShevchenkoThe charlcd_free() is a counterpart to charlcd_alloc() and should be called symmetrically on tear down.
--- drivers/auxdisplay/charlcd.c | 6 ++++++ include/misc/charlcd.h | 1 + 2 files changed, 7 insertions(+)
drivers/auxdisplay/charlcd.c +6 -0
@@ -818,6 +818,12 @@ struct charlcd *charlcd_alloc(unsigned int drvdata_size) }EXPORT_SYMBOL_GPL (charlcd_alloc); +void charlcd_free (struct charlcd *lcd) +{ +kfree (lcd); +} +EXPORT_SYMBOL_GPL (charlcd_free); +static int panel_notify_sys (struct notifier_block *this,unsigned long code,void *unused) {
include/misc/charlcd.h +1 -0
@@ -35,6 +35,7 @@ struct charlcd_ops { };struct charlcd *charlcd_alloc (unsigned int drvdata_size); +void charlcd_free (struct charlcd *lcd);int charlcd_register (struct charlcd *lcd);int charlcd_unregister (struct charlcd *lcd);
Signature · 1 line
2.20.1
PATCH 1/4 auxdisplay: hd44780: Fix memory leak on ->remove()
We have to free on ->remove() the allocated resources on ->probe().
--- drivers/auxdisplay/hd44780.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/auxdisplay/hd44780.c +2 -0
@@ -280,6 +280,8 @@ static int hd44780_remove(struct platform_device *pdev)struct charlcd *lcd =platform_get_drvdata (pdev);charlcd_unregister (lcd); + +kfree (lcd);return 0 ; }
Signature · 1 line
2.20.1
PATCH 3/4 auxdisplay: panel: Convert to use charlcd_free()
Convert to use charlcd_free() instead of kfree() for sake of type check.
--- drivers/auxdisplay/panel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/panel.c +2 -2
@@ -1620,7 +1620,7 @@ static void panel_attach(struct parport *port)if (lcd.enabled)charlcd_unregister (lcd.charlcd); err_unreg_device: -kfree (lcd.charlcd); +charlcd_free (lcd.charlcd); lcd.charlcd =NULL ;parport_unregister_device (pprt); pprt =NULL ;
@@ -1647,7 +1647,7 @@ static void panel_detach(struct parport *port)if (lcd.enabled) {charlcd_unregister (lcd.charlcd); lcd.initialized = false; -kfree (lcd.charlcd); +charlcd_free (lcd.charlcd); lcd.charlcd =NULL ; }
Signature · 1 line
2.20.1
PATCH 4/4 auxdisplay: hd44780: Convert to use charlcd_free()
In reply to Andy ShevchenkoConvert to use charlcd_free() instead of kfree() for sake of type check.
--- drivers/auxdisplay/hd44780.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/hd44780.c +2 -2
@@ -271,7 +271,7 @@ static int hd44780_probe(struct platform_device *pdev)return 0 ; fail: -kfree (lcd); +charlcd_free (lcd);return ret; }
@@ -281,7 +281,7 @@ static int hd44780_remove(struct platform_device *pdev)charlcd_unregister (lcd); -kfree (lcd); +charlcd_free (lcd);return 0 ; }
Signature · 1 line
2.20.1
Geert Uytterhoeven
reviewerHi Andy,
Quoted 5 lines · Andy Shevchenko
We have to free on ->remove() the allocated resources on ->probe().
Fixes d47d88361fee ("auxdisplay: Add HD44780 Character LCD support")Cc Geert Uytterhoeven <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Thanks, nice catch!
drivers/auxdisplay/hd44780.c static int hd44780_remove(struct platform_device *pdev) · line 284
Quoted 8 lines
drivers/auxdisplay/hd44780.c +2
-0@@ -280,6 +280,8 @@ static int hd44780_remove(struct platform_device *pdev)struct charlcd *lcd =platform_get_drvdata (pdev);charlcd_unregister (lcd); + +kfree (lcd);
(wearing a newer (and hopefully wiser ;-) hat than when I wrote the code)
While this is correct for the current implementation of struct charlcd_priv, this may be a bit fragile.
What about adding a charlcd_free() wrapper, which can do kfree(to_priv(lcd)), and be used in the probe failure path, too?
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 8 lines · Geert Uytterhoeven
Quoted 5 lines · Andy Shevchenko
We have to free on ->remove() the allocated resources on ->probe().
Fixes d47d88361fee ("auxdisplay: Add HD44780 Character LCD support")Cc Geert Uytterhoeven <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 6 lines
Thanks, nice catch!
(wearing a newer (and hopefully wiser ;-) hat than when I wrote the code)
While this is correct for the current implementation of struct
charlcd_priv, this may be a bit fragile.
This patch will be the same in the next version due to possibility to easy backport.
Quoted 2 lines
What about adding a
charlcd_free()wrapper, which can do kfree(to_priv(lcd)), and be used in the probe failure path, too?
This has been partially done in the rest of the series, but I got your advise and will change to use to_priv() in v2. Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Geert Uytterhoeven
reviewerHi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Geert Uytterhoeven
Quoted 5 lines · Andy Shevchenko
We have to free on ->remove() the allocated resources on ->probe().
Fixes d47d88361fee ("auxdisplay: Add HD44780 Character LCD support")Cc Geert Uytterhoeven <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Thanks, nice catch!
Quoted 7 lines
Quoted 4 lines
(wearing a newer (and hopefully wiser ;-) hat than when I wrote the code)
While this is correct for the current implementation of struct
charlcd_priv, this may be a bit fragile.This patch will be the same in the next version due to possibility to easy backport.
OK.
Quoted 5 lines
Quoted 2 lines
What about adding a
charlcd_free()wrapper, which can do kfree(to_priv(lcd)), and be used in the probe failure path, too?This has been partially done in the rest of the series, but I got your advise and will change to use
to_priv()in v2. Thanks!
Ah, hadn't noticed the rest of the series. Will review...
Gr{oetje,eeting}s,
Geert
--
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