* [PATCH] NTB: ntb_transport: fix possible memory leak while device_register() fails
@ 2022-11-10 15:19 Yang Yingliang
2022-11-10 15:33 ` Dave Jiang
0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-11-10 15:19 UTC (permalink / raw)
To: ntb; +Cc: jdmason, dave.jiang, allenbh, yangyingliang
If device_register() returns error, the name allocated by
dev_set_name() need be freed. As comment of device_register()
says, it should use put_device() to give up the reference in
the error path. So fix this by calling put_device(), then the
name can be freed in kobject_cleanup(), and client_dev is freed
in ntb_transport_client_release().
Fixes: fce8a7bb5b4b ("PCI-Express Non-Transparent Bridge Support")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/ntb/ntb_transport.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index a9b97ebc71ac..2abd2235bbca 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -410,7 +410,7 @@ int ntb_transport_register_client_dev(char *device_name)
rc = device_register(dev);
if (rc) {
- kfree(client_dev);
+ put_device(dev);
goto err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] NTB: ntb_transport: fix possible memory leak while device_register() fails
2022-11-10 15:19 [PATCH] NTB: ntb_transport: fix possible memory leak while device_register() fails Yang Yingliang
@ 2022-11-10 15:33 ` Dave Jiang
0 siblings, 0 replies; 2+ messages in thread
From: Dave Jiang @ 2022-11-10 15:33 UTC (permalink / raw)
To: Yang Yingliang, ntb; +Cc: jdmason, allenbh
On 11/10/2022 7:19 AM, Yang Yingliang wrote:
> If device_register() returns error, the name allocated by
> dev_set_name() need be freed. As comment of device_register()
> says, it should use put_device() to give up the reference in
> the error path. So fix this by calling put_device(), then the
> name can be freed in kobject_cleanup(), and client_dev is freed
> in ntb_transport_client_release().
>
> Fixes: fce8a7bb5b4b ("PCI-Express Non-Transparent Bridge Support")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/ntb/ntb_transport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index a9b97ebc71ac..2abd2235bbca 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -410,7 +410,7 @@ int ntb_transport_register_client_dev(char *device_name)
>
> rc = device_register(dev);
> if (rc) {
> - kfree(client_dev);
> + put_device(dev);
> goto err;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-10 15:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 15:19 [PATCH] NTB: ntb_transport: fix possible memory leak while device_register() fails Yang Yingliang
2022-11-10 15:33 ` Dave Jiang
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.