All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] mips: txx9: fix resource leak after register fail
@ 2018-09-05 11:22 Ding Xiang
  2018-09-05 15:37 ` Atsushi Nemoto
  0 siblings, 1 reply; 3+ messages in thread
From: Ding Xiang @ 2018-09-05 11:22 UTC (permalink / raw)
  To: ralf, paul.burton, jhogan, linux-mips, linux-kernel; +Cc: dingxiang

the memory allocated and ioremap address need free after
device_register return error.

v2: remove redundant "return"

Signed-off-by: Ding Xiang <dingxiang@cmss.chinamobile.com>
---
 arch/mips/txx9/generic/setup.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c
index f6d9182..e116a55 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -961,11 +961,12 @@ void __init txx9_sramc_init(struct resource *r)
 	err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
 	if (err) {
 		device_unregister(&dev->dev);
-		iounmap(dev->base);
-		kfree(dev);
+		goto exit_free;
 	}
 	return;
 exit_put:
 	put_device(&dev->dev);
-	return;
+exit_free:
+	iounmap(dev->base);
+	kfree(dev);
 }
-- 
1.9.1




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

* Re: [PATCH V2] mips: txx9: fix resource leak after register fail
  2018-09-05 11:22 [PATCH V2] mips: txx9: fix resource leak after register fail Ding Xiang
@ 2018-09-05 15:37 ` Atsushi Nemoto
  2018-09-06  2:17   ` Ding Xiang
  0 siblings, 1 reply; 3+ messages in thread
From: Atsushi Nemoto @ 2018-09-05 15:37 UTC (permalink / raw)
  To: dingxiang; +Cc: ralf, paul.burton, jhogan, linux-mips, linux-kernel

On Wed,  5 Sep 2018 19:22:19 +0800, Ding Xiang <dingxiang@cmss.chinamobile.com> wrote:
> the memory allocated and ioremap address need free after
> device_register return error.
...
>  exit_put:
>  	put_device(&dev->dev);
> -	return;
> +exit_free:
> +	iounmap(dev->base);
> +	kfree(dev);

This change will break exit_put error path.
I think kfree will be called from txx9_device_release by put_device.

Please refer James's comment on previous trial:
<https://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=20180305221833.GJ4197%40saruman>

---
Atsushi Nemoto

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

* Re: [PATCH V2] mips: txx9: fix resource leak after register fail
  2018-09-05 15:37 ` Atsushi Nemoto
@ 2018-09-06  2:17   ` Ding Xiang
  0 siblings, 0 replies; 3+ messages in thread
From: Ding Xiang @ 2018-09-06  2:17 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: ralf, paul.burton, jhogan, linux-mips, linux-kernel


On 9/5/2018 11:37 PM, Atsushi Nemoto wrote:
> On Wed,  5 Sep 2018 19:22:19 +0800, Ding Xiang <dingxiang@cmss.chinamobile.com> wrote:
>> the memory allocated and ioremap address need free after
>> device_register return error.
> ...
>>   exit_put:
>>   	put_device(&dev->dev);
>> -	return;
>> +exit_free:
>> +	iounmap(dev->base);
>> +	kfree(dev);
> This change will break exit_put error path.
> I think kfree will be called from txx9_device_release by put_device.
>
> Please refer James's comment on previous trial:
> <https://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=20180305221833.GJ4197%40saruman>

yes, put_device will call txx9_device_release and free txx9_sramc_dev, 
and kfree in  sysfs_create_bin_file() error handle

is also unneeded, I will send a new patch soon




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

end of thread, other threads:[~2018-09-06  2:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-05 11:22 [PATCH V2] mips: txx9: fix resource leak after register fail Ding Xiang
2018-09-05 15:37 ` Atsushi Nemoto
2018-09-06  2:17   ` Ding Xiang

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.