linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ide: pci: Fix memleak in ide_pci_init_two
@ 2020-12-20  7:05 Dinghao Liu
  2020-12-20 19:50 ` Kari Argillander
  0 siblings, 1 reply; 4+ messages in thread
From: Dinghao Liu @ 2020-12-20  7:05 UTC (permalink / raw)
  To: dinghao.liu, kjlu; +Cc: David S. Miller, linux-ide, linux-kernel

When do_ide_setup_pci_device() fails, host allocated
by ide_host_alloc() may not have been freed, which
leads to memleak.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/ide/setup-pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index fdc8e813170c..c7da5368fcd4 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -586,7 +586,7 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
 		 * do_ide_setup_pci_device() on the first device!
 		 */
 		if (ret < 0)
-			goto out_free_bars;
+			goto out_free_host;
 
 		/* fixup IRQ */
 		if (ide_pci_is_in_compatibility_mode(pdev[i])) {
@@ -597,11 +597,11 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
 	}
 
 	ret = ide_host_register(host, d, hws);
-	if (ret)
-		ide_host_free(host);
-	else
+	if (!ret)
 		goto out;
 
+out_free_host:
+	ide_host_free(host);
 out_free_bars:
 	i = n_ports / 2;
 	while (i--)
-- 
2.17.1


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

* Re: [PATCH] ide: pci: Fix memleak in ide_pci_init_two
  2020-12-20  7:05 [PATCH] ide: pci: Fix memleak in ide_pci_init_two Dinghao Liu
@ 2020-12-20 19:50 ` Kari Argillander
  2020-12-23  8:59   ` dinghao.liu
  0 siblings, 1 reply; 4+ messages in thread
From: Kari Argillander @ 2020-12-20 19:50 UTC (permalink / raw)
  To: Dinghao Liu; +Cc: kjlu, David S. Miller, linux-ide, linux-kernel

On Sun, Dec 20, 2020 at 03:05:40PM +0800, Dinghao Liu wrote:
> When do_ide_setup_pci_device() fails, host allocated
> by ide_host_alloc() may not have been freed, which
> leads to memleak.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/ide/setup-pci.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
> index fdc8e813170c..c7da5368fcd4 100644
> --- a/drivers/ide/setup-pci.c
> +++ b/drivers/ide/setup-pci.c
> @@ -586,7 +586,7 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
>  		 * do_ide_setup_pci_device() on the first device!
>  		 */
>  		if (ret < 0)
> -			goto out_free_bars;
> +			goto out_free_host;
>  
>  		/* fixup IRQ */
>  		if (ide_pci_is_in_compatibility_mode(pdev[i])) {
> @@ -597,11 +597,11 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
>  	}
>  
>  	ret = ide_host_register(host, d, hws);
> -	if (ret)
> -		ide_host_free(host);
> -	else
> +	if (!ret)
>  		goto out;

Maybe 
	if (ret)
		goto out_free_host;

	return 0;

would be more clear here. But this is just small nit.

>  
> +out_free_host:
> +	ide_host_free(host);
>  out_free_bars:
>  	i = n_ports / 2;
>  	while (i--)


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

* Re: Re: [PATCH] ide: pci: Fix memleak in ide_pci_init_two
  2020-12-20 19:50 ` Kari Argillander
@ 2020-12-23  8:59   ` dinghao.liu
  0 siblings, 0 replies; 4+ messages in thread
From: dinghao.liu @ 2020-12-23  8:59 UTC (permalink / raw)
  To: Kari Argillander; +Cc: kjlu, David S. Miller, linux-ide, linux-kernel

> On Sun, Dec 20, 2020 at 03:05:40PM +0800, Dinghao Liu wrote:
> > When do_ide_setup_pci_device() fails, host allocated
> > by ide_host_alloc() may not have been freed, which
> > leads to memleak.
> > 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/ide/setup-pci.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
> > index fdc8e813170c..c7da5368fcd4 100644
> > --- a/drivers/ide/setup-pci.c
> > +++ b/drivers/ide/setup-pci.c
> > @@ -586,7 +586,7 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
> >  		 * do_ide_setup_pci_device() on the first device!
> >  		 */
> >  		if (ret < 0)
> > -			goto out_free_bars;
> > +			goto out_free_host;
> >  
> >  		/* fixup IRQ */
> >  		if (ide_pci_is_in_compatibility_mode(pdev[i])) {
> > @@ -597,11 +597,11 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
> >  	}
> >  
> >  	ret = ide_host_register(host, d, hws);
> > -	if (ret)
> > -		ide_host_free(host);
> > -	else
> > +	if (!ret)
> >  		goto out;
> 
> Maybe 
> 	if (ret)
> 		goto out_free_host;
> 
> 	return 0;
> 
> would be more clear here. But this is just small nit.
> 
> >  
> > +out_free_host:
> > +	ide_host_free(host);
> >  out_free_bars:
> >  	i = n_ports / 2;
> >  	while (i--)

Thank you for your advice and I will send a new patch soon.

Regards,
Dinghao

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

* [PATCH] ide: pci: Fix memleak in ide_pci_init_two
@ 2020-08-26  9:17 Dinghao Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Dinghao Liu @ 2020-08-26  9:17 UTC (permalink / raw)
  To: dinghao.liu, kjlu; +Cc: David S. Miller, linux-ide, linux-kernel

When do_ide_setup_pci_device() fails, host should be
freed just like when ide_host_register() fails.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/ide/setup-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index fdc8e813170c..e6cba7e24c39 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -585,8 +585,10 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
 		 * FIXME: Mom, mom, they stole me the helper function to undo
 		 * do_ide_setup_pci_device() on the first device!
 		 */
-		if (ret < 0)
+		if (ret < 0) {
+			ide_host_free(host);
 			goto out_free_bars;
+		}
 
 		/* fixup IRQ */
 		if (ide_pci_is_in_compatibility_mode(pdev[i])) {
-- 
2.17.1


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

end of thread, other threads:[~2020-12-23  9:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20  7:05 [PATCH] ide: pci: Fix memleak in ide_pci_init_two Dinghao Liu
2020-12-20 19:50 ` Kari Argillander
2020-12-23  8:59   ` dinghao.liu
  -- strict thread matches above, loose matches on Subject: below --
2020-08-26  9:17 Dinghao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).