[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y2yzwB0IuaVS3AVq@kroah.com>
Date: Thu, 10 Nov 2022 09:18:08 +0100
From: Greg KH <gregkh@...uxfoundation.org>
To: Yang Yingliang <yangyingliang@...wei.com>
Cc: open-iscsi@...glegroups.com, linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org, lduncan@...e.com, cleech@...hat.com,
michael.christie@...cle.com, jejb@...ux.ibm.com,
martin.petersen@...cle.com, rafael@...nel.org
Subject: Re: [PATCH] drivers: base: transport_class: fix possible memory leak
On Thu, Nov 10, 2022 at 11:48:09AM +0800, Yang Yingliang wrote:
> Current some drivers(like iscsi) call transport_register_device()
> failed, they don't call transport_destroy_device() to release the
> memory allocated in transport_setup_device(), because they don't
> know what was done, it should be internal thing to release the
> resource in register function. So fix this leak by calling destroy
> function inside register function.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yang Yingliang <yangyingliang@...wei.com>
> ---
> include/linux/transport_class.h | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/transport_class.h b/include/linux/transport_class.h
> index 63076fb835e3..f4835250bbfc 100644
> --- a/include/linux/transport_class.h
> +++ b/include/linux/transport_class.h
> @@ -70,8 +70,15 @@ void transport_destroy_device(struct device *);
> static inline int
> transport_register_device(struct device *dev)
> {
> + int ret;
> +
> transport_setup_device(dev);
> - return transport_add_device(dev);
> + ret = transport_add_device(dev);
> + if (ret) {
> + transport_destroy_device(dev);
> + }
Please use scripts/checkpatch.pl on your patches before sending them out
so you don't get grumpy maintainers asking you to use
scripts/checkpatch.pl on your patches :)
thanks,
greg k-h
Powered by blists - more mailing lists