diff mbox series

staging: fbtft: core: fix potential memory leak in fbtft_probe_common()

Message ID 20220928062301.6399-1-niejianglei2021@163.com
State New
Headers show
Series staging: fbtft: core: fix potential memory leak in fbtft_probe_common() | expand

Commit Message

Jianglei Nie Sept. 28, 2022, 6:23 a.m. UTC
fbtft_probe_common() allocates a memory chunk for "info" with
fbtft_framebuffer_alloc(). When "display->buswidth == 0" is true, the
function returns without releasing the "info", which will lead to a
memory leak.

Fix it by calling fbtft_framebuffer_release() when "display->buswidth
== 0" is true.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/staging/fbtft/fbtft-core.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko April 4, 2024, 4:35 p.m. UTC | #1
On Wed, Sep 28, 2022 at 02:23:01PM +0800, Jianglei Nie wrote:
> fbtft_probe_common() allocates a memory chunk for "info" with
> fbtft_framebuffer_alloc(). When "display->buswidth == 0" is true, the
> function returns without releasing the "info", which will lead to a
> memory leak.
> 
> Fix it by calling fbtft_framebuffer_release() when "display->buswidth
> == 0" is true.

Fixes tag?

...

>  	if (display->buswidth == 0) {
>  		dev_err(dev, "buswidth is not set\n");
> +		fbtft_framebuffer_release(info);
>  		return -EINVAL;

		ret = dev_err_probe(dev, -EINVAL, "buswidth is not set\n");
		goto out_release;

>  	}
diff mbox series

Patch

diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index afaba94d1d1c..ecf595aff786 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -1225,6 +1225,7 @@  int fbtft_probe_common(struct fbtft_display *display,
 
 	if (display->buswidth == 0) {
 		dev_err(dev, "buswidth is not set\n");
+		fbtft_framebuffer_release(info);
 		return -EINVAL;
 	}