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[] = {
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.
linux-stable-mirror@lists.linaro.org