Skip to contentSkip to conversation

ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe

PATCH Applied Miaoqian Lin 3 participants 3 messages Jun 1, 2022 – Jun 2, 2022 libata

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe

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.")

---
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/[email protected]/

---
 drivers/ata/pata_octeon_cf.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/ata/pata_octeon_cf.c +3 -0
index 6b5ed3046b44..35608a0cf552 100644
@@ -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);
 		}
Signature · 1 line
2.25.1
#2 lore raw
In reply to Miaoqian Lin
Quoted 39 lines · Miaoqian Lin

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.")

---
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/[email protected]/

---
 drivers/ata/pata_octeon_cf.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/ata/pata_octeon_cf.c +2 -0
index 6b5ed3046b44..35608a0cf552 100644
@@ -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;
 				}

drivers/ata/pata_octeon_cf.c static int octeon_cf_probe(struct platform_device *pdev) · line 879

Quoted 7 lines
drivers/ata/pata_octeon_cf.c +1 -0
@@ -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);
 		}

Applied to for-5.19-fixes. Thanks !

Signature · 2 lines
Damien Le Moal
Western Digital Research