Linux ATA/IDE development
 help / color / mirror / Atom feed
* [PATCH] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe
@ 2022-05-11  6:27 Miaoqian Lin
  2022-05-11  7:36 ` Damien Le Moal
  2022-05-11 11:46 ` Sergey Shtylyov
  0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-05-11  6:27 UTC (permalink / raw)
  To: Sergey Shtylyov, Damien Le Moal, Jeff Garzik, David Daney,
	linux-ide, linux-kernel
  Cc: linmq006

of_find_device_by_node() takes reference, we should use put_device()
to release it when not need anymore.
Add missing put_device() in error path to avoid refcount
leak.

Fixes: 43f01da0f279 ("MIPS/OCTEON/ata: Convert pata_octeon_cf.c to use device tree.")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/ata/pata_octeon_cf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
index 6b5ed3046b44..65688459acf1 100644
--- a/drivers/ata/pata_octeon_cf.c
+++ b/drivers/ata/pata_octeon_cf.c
@@ -857,12 +857,14 @@ static int octeon_cf_probe(struct platform_device *pdev)
 				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
 				if (!res_dma) {
 					of_node_put(dma_node);
+					put_device(&dma_dev->dev);
 					return -EINVAL;
 				}
 				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
 									 resource_size(res_dma));
 				if (!cf_port->dma_base) {
 					of_node_put(dma_node);
+					put_device(&dma_dev->dev);
 					return -EINVAL;
 				}
 
-- 
2.25.1


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

* Re: [PATCH] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe
  2022-05-11  6:27 [PATCH] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe Miaoqian Lin
@ 2022-05-11  7:36 ` Damien Le Moal
  2022-05-11 11:46 ` Sergey Shtylyov
  1 sibling, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2022-05-11  7:36 UTC (permalink / raw)
  To: Miaoqian Lin, Sergey Shtylyov, Jeff Garzik, David Daney,
	linux-ide, linux-kernel

On 2022/05/11 8:27, Miaoqian Lin wrote:
> of_find_device_by_node() takes reference, we should use put_device()
> to release it when not need anymore.
> Add missing put_device() in error path to avoid refcount
> leak.
> 
> Fixes: 43f01da0f279 ("MIPS/OCTEON/ata: Convert pata_octeon_cf.c to use device tree.")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/ata/pata_octeon_cf.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
> index 6b5ed3046b44..65688459acf1 100644
> --- a/drivers/ata/pata_octeon_cf.c
> +++ b/drivers/ata/pata_octeon_cf.c
> @@ -857,12 +857,14 @@ static int octeon_cf_probe(struct platform_device *pdev)
>  				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
>  				if (!res_dma) {
>  					of_node_put(dma_node);
> +					put_device(&dma_dev->dev);
>  					return -EINVAL;
>  				}
>  				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
>  									 resource_size(res_dma));
>  				if (!cf_port->dma_base) {
>  					of_node_put(dma_node);
> +					put_device(&dma_dev->dev);
>  					return -EINVAL;
>  				}
>  

The extra reference should also be dropped at the end of the "if (dma_node)"
too, no ? Otherwise, early returns due to errors after that "if (dma_node)" will
also leak the extra ref.

Note that looking around at places where of_find_device_by_node() is being used,
very few users call put_device()... Looks like there are lots of device ref
leaks with that.

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe
  2022-05-11  6:27 [PATCH] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe Miaoqian Lin
  2022-05-11  7:36 ` Damien Le Moal
@ 2022-05-11 11:46 ` Sergey Shtylyov
  1 sibling, 0 replies; 3+ messages in thread
From: Sergey Shtylyov @ 2022-05-11 11:46 UTC (permalink / raw)
  To: Miaoqian Lin, Damien Le Moal, Jeff Garzik, David Daney, linux-ide,
	linux-kernel

Hello!

On 5/11/22 9:27 AM, Miaoqian Lin wrote:

> of_find_device_by_node() takes reference, we should use put_device()
> to release it when not need anymore.
> Add missing put_device() in error path to avoid refcount
> leak.
> 
> Fixes: 43f01da0f279 ("MIPS/OCTEON/ata: Convert pata_octeon_cf.c to use device tree.")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/ata/pata_octeon_cf.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
> index 6b5ed3046b44..65688459acf1 100644
> --- a/drivers/ata/pata_octeon_cf.c
> +++ b/drivers/ata/pata_octeon_cf.c
> @@ -857,12 +857,14 @@ static int octeon_cf_probe(struct platform_device *pdev)
>  				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
>  				if (!res_dma) {
>  					of_node_put(dma_node);
> +					put_device(&dma_dev->dev);
>  					return -EINVAL;
>  				}
>  				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
>  									 resource_size(res_dma));
>  				if (!cf_port->dma_base) {
>  					of_node_put(dma_node);
> +					put_device(&dma_dev->dev);
>  					return -EINVAL;
>  				}
>  

   It seems you forgot to call put_device() at the end of the enclosing *if*, where of_node_put()
is also called...

MBR, Sergey

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

end of thread, other threads:[~2022-05-11 11:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-11  6:27 [PATCH] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe Miaoqian Lin
2022-05-11  7:36 ` Damien Le Moal
2022-05-11 11:46 ` Sergey Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox