* [PATCH v3] auxdisplay: hd44780: Fix a potential memory leak in hd44780.c
@ 2025-02-26 10:12 Haoxiang Li
2025-02-26 13:27 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2025-02-26 10:12 UTC (permalink / raw)
To: andy, geert, u.kleine-koenig, erick.archer, haoxiang_li2024,
ojeda, w, poeschel
Cc: linux-kernel, stable
At the 'fail2' label in hd44780_probe(), the 'lcd' variable is
freed via kfree(), but this does not actually release the memory
allocated by charlcd_alloc(), as that memory is a container for lcd.
As a result, a memory leak occurs. Replace kfree() with charlcd_free()
to fix a potential memory leak.
Same replacement is done in hd44780_remove().
Fixes: 718e05ed92ec ("auxdisplay: Introduce hd44780_common.[ch]")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
Changes in v3:
- modify the patch description.
Thanks for the review! I think Fixes-tag should be added because
the previous version causes a memory leak. I modified the patch
description to illustrate it. Thanks again!
Changes in v2:
- Merge the two patches into one.
- Modify the patch description.
Sorry Geert, I didn't see your reply until after I sent the
second patch. I've merged the two patches into one, hoping
to make your work a bit easier! Thanks a lot!
---
drivers/auxdisplay/hd44780.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/auxdisplay/hd44780.c b/drivers/auxdisplay/hd44780.c
index 0526f0d90a79..9d0ae9c02e9b 100644
--- a/drivers/auxdisplay/hd44780.c
+++ b/drivers/auxdisplay/hd44780.c
@@ -313,7 +313,7 @@ static int hd44780_probe(struct platform_device *pdev)
fail3:
kfree(hd);
fail2:
- kfree(lcd);
+ charlcd_free(lcd);
fail1:
kfree(hdc);
return ret;
@@ -328,7 +328,7 @@ static void hd44780_remove(struct platform_device *pdev)
kfree(hdc->hd44780);
kfree(lcd->drvdata);
- kfree(lcd);
+ charlcd_free(lcd);
}
static const struct of_device_id hd44780_of_match[] = {
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] auxdisplay: hd44780: Fix a potential memory leak in hd44780.c
2025-02-26 10:12 [PATCH v3] auxdisplay: hd44780: Fix a potential memory leak in hd44780.c Haoxiang Li
@ 2025-02-26 13:27 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2025-02-26 13:27 UTC (permalink / raw)
To: Haoxiang Li
Cc: geert, u.kleine-koenig, erick.archer, ojeda, w, poeschel,
linux-kernel, stable
On Wed, Feb 26, 2025 at 06:12:13PM +0800, Haoxiang Li wrote:
> At the 'fail2' label in hd44780_probe(), the 'lcd' variable is
> freed via kfree(), but this does not actually release the memory
> allocated by charlcd_alloc(), as that memory is a container for lcd.
> As a result, a memory leak occurs. Replace kfree() with charlcd_free()
> to fix a potential memory leak.
> Same replacement is done in hd44780_remove().
The v2 was already applied.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-26 13:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 10:12 [PATCH v3] auxdisplay: hd44780: Fix a potential memory leak in hd44780.c Haoxiang Li
2025-02-26 13:27 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox