All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/mipi-dsi: fix possible memory leak in mipi_dsi_device_register_full()
@ 2022-10-18  8:25 Yang Yingliang
  2022-10-18 10:22 ` Thierry Reding
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-10-18  8:25 UTC (permalink / raw)
  To: dri-devel; +Cc: a.hajda, kyungmin.park, yangyingliang, treding

If mipi_dsi_device_add() fails, the refcount of device is not 0, the name
allocated in dev_set_name() is leaked. Fix this by calling put_device(),
so that it will be freed in callback function kobject_cleanup().

Fixes: 068a00233969 ("drm: Add MIPI DSI bus support")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/gpu/drm/drm_mipi_dsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 3ec02748d56f..431952f6fd25 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -228,7 +228,7 @@ mipi_dsi_device_register_full(struct mipi_dsi_host *host,
 	ret = mipi_dsi_device_add(dsi);
 	if (ret) {
 		drm_err(host, "failed to add DSI device %d\n", ret);
-		kfree(dsi);
+		put_device(&dsi->dev);
 		return ERR_PTR(ret);
 	}
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/mipi-dsi: fix possible memory leak in mipi_dsi_device_register_full()
  2022-10-18  8:25 [PATCH] drm/mipi-dsi: fix possible memory leak in mipi_dsi_device_register_full() Yang Yingliang
@ 2022-10-18 10:22 ` Thierry Reding
  0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2022-10-18 10:22 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: a.hajda, kyungmin.park, dri-devel

[-- Attachment #1: Type: text/plain, Size: 765 bytes --]

On Tue, Oct 18, 2022 at 04:25:45PM +0800, Yang Yingliang wrote:
> If mipi_dsi_device_add() fails, the refcount of device is not 0, the name
> allocated in dev_set_name() is leaked. Fix this by calling put_device(),
> so that it will be freed in callback function kobject_cleanup().
> 
> Fixes: 068a00233969 ("drm: Add MIPI DSI bus support")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/gpu/drm/drm_mipi_dsi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Good catch! The device_initialize() function (which is called via
mipi_dsi_device_alloc() earlier in mipi_dsi_device_register_full()) has
a comment that put_device() should be used after it was called.

Reviewed-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-18 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18  8:25 [PATCH] drm/mipi-dsi: fix possible memory leak in mipi_dsi_device_register_full() Yang Yingliang
2022-10-18 10:22 ` Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.