mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe
@ 2022-06-01  8:59 Miaoqian Lin
  2022-06-01 19:01 ` Sergey Shtylyov
  2022-06-02  6:32 ` Damien Le Moal
  0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-06-01  8:59 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() 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>
---
changes in v2:
- Add put_device() at the end of if (dma_dev).
  we need the null check and do handling only if dma_dev!=NULL.
- call put_device before of_node_put() in error path. keep the
  reverse order of resource allocation.

v1 link:
https://lore.kernel.org/all/20220511062723.56652-1-linmq006@gmail.com/
---
 drivers/ata/pata_octeon_cf.c | 3 +++
 1 file changed, 3 insertions(+)

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


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

end of thread, other threads:[~2022-06-02  6:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01  8:59 [PATCH v2] ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe Miaoqian Lin
2022-06-01 19:01 ` Sergey Shtylyov
2022-06-02  6:32 ` Damien Le Moal

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

all inboxes | Powered by JetHome®