All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: base: transport_class: fix possible memory leak
@ 2022-11-10  3:48 Yang Yingliang
  2022-11-10  8:18 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-10  3:48 UTC (permalink / raw)
  To: open-iscsi, linux-scsi, linux-kernel
  Cc: lduncan, cleech, michael.christie, jejb, martin.petersen, gregkh,
	rafael, yangyingliang

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@huawei.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);
+	}
+
+	return ret;
 }
 
 static inline void
-- 
2.25.1


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

* Re: [PATCH] drivers: base: transport_class: fix possible memory leak
  2022-11-10  3:48 [PATCH] drivers: base: transport_class: fix possible memory leak Yang Yingliang
@ 2022-11-10  8:18 ` Greg KH
  2022-11-10  8:44   ` Yang Yingliang
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2022-11-10  8:18 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: open-iscsi, linux-scsi, linux-kernel, lduncan, cleech,
	michael.christie, jejb, martin.petersen, rafael

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@huawei.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

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

* Re: [PATCH] drivers: base: transport_class: fix possible memory leak
  2022-11-10  8:18 ` Greg KH
@ 2022-11-10  8:44   ` Yang Yingliang
  2022-11-10  9:18     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-10  8:44 UTC (permalink / raw)
  To: Greg KH
  Cc: open-iscsi, linux-scsi, linux-kernel, lduncan, cleech,
	michael.christie, jejb, martin.petersen, rafael

Hi Greg,

On 2022/11/10 16:18, Greg KH wrote:
> 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@huawei.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
Sure, of course. :)
> so you don't get grumpy maintainers asking you to use
> scripts/checkpatch.pl on your patches :)
I sent a fix patch to iscsi system earlier:
https://patchwork.kernel.org/project/linux-scsi/patch/20221109092421.3111613-1-yangyingliang@huawei.com/

Mike give his point in the mail, so I send a new patch keep iscsi 
maintainers Cced.

Thanks,
Yang
>
> thanks,
>
> greg k-h
>
> .

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

* Re: [PATCH] drivers: base: transport_class: fix possible memory leak
  2022-11-10  8:44   ` Yang Yingliang
@ 2022-11-10  9:18     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2022-11-10  9:18 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: open-iscsi, linux-scsi, linux-kernel, lduncan, cleech,
	michael.christie, jejb, martin.petersen, rafael

On Thu, Nov 10, 2022 at 04:44:16PM +0800, Yang Yingliang wrote:
> Hi Greg,
> 
> On 2022/11/10 16:18, Greg KH wrote:
> > 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@huawei.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
> Sure, of course. :)
> > so you don't get grumpy maintainers asking you to use
> > scripts/checkpatch.pl on your patches :)
> I sent a fix patch to iscsi system earlier:
> https://patchwork.kernel.org/project/linux-scsi/patch/20221109092421.3111613-1-yangyingliang@huawei.com/
> 
> Mike give his point in the mail, so I send a new patch keep iscsi
> maintainers Cced.

That's fine, but the code you wrote here should look different as it
does not follow our coding style rules.  That is the point I was trying
to make.

thanks,

greg k-h

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  3:48 [PATCH] drivers: base: transport_class: fix possible memory leak Yang Yingliang
2022-11-10  8:18 ` Greg KH
2022-11-10  8:44   ` Yang Yingliang
2022-11-10  9:18     ` Greg KH

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.