for_each_node_by_name() will automatically increase and decrease the refcount. We should call of_node_put() when there is a break during the iteration. Signed-off-by: Liang He <windhl@xxxxxxx> --- arch/sparc/include/asm/floppy_32.h | 8 ++++++-- arch/sparc/include/asm/floppy_64.h | 31 ++++++++++++++++++------------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/arch/sparc/include/asm/floppy_32.h b/arch/sparc/include/asm/floppy_32.h index e10ab9ad3097..5e17d35833c8 100644 --- a/arch/sparc/include/asm/floppy_32.h +++ b/arch/sparc/include/asm/floppy_32.h @@ -324,14 +324,18 @@ static int sun_floppy_init(void) op = NULL; for_each_node_by_name(dp, "SUNW,fdtwo") { op = of_find_device_by_node(dp); - if (op) + if (op) { + of_node_put(dp); break; + } } if (!op) { for_each_node_by_name(dp, "fd") { op = of_find_device_by_node(dp); - if (op) + if (op) { + of_node_put(dp); break; + } } } if (!op) diff --git a/arch/sparc/include/asm/floppy_64.h b/arch/sparc/include/asm/floppy_64.h index 070c8c1f5c8f..39dfaead1c6c 100644 --- a/arch/sparc/include/asm/floppy_64.h +++ b/arch/sparc/include/asm/floppy_64.h @@ -548,7 +548,7 @@ static int __init ebus_fdthree_p(struct device_node *dp) static unsigned long __init sun_floppy_init(void) { static int initialized = 0; - struct device_node *dp; + struct device_node *dp, *ebus_dp; struct platform_device *op; const char *prop; char state[128]; @@ -563,14 +563,15 @@ static unsigned long __init sun_floppy_init(void) if (!of_node_name_eq(dp->parent, "sbus")) continue; op = of_find_device_by_node(dp); - if (op) + if (op) { + of_node_put(dp); break; + } } if (op) { floppy_op = op; FLOPPY_IRQ = op->archdata.irqs[0]; } else { - struct device_node *ebus_dp; void __iomem *auxio_reg; const char *state_prop; unsigned long config; @@ -584,15 +585,15 @@ static unsigned long __init sun_floppy_init(void) } found_fdthree: if (!dp) - return 0; + goto out_put_node; op = of_find_device_by_node(dp); if (!op) - return 0; + goto out_put_node; state_prop = of_get_property(op->dev.of_node, "status", NULL); if (state_prop && !strncmp(state_prop, "disabled", 8)) - return 0; + goto out_put_node; FLOPPY_IRQ = op->archdata.irqs[0]; @@ -610,7 +611,7 @@ static unsigned long __init sun_floppy_init(void) sun_pci_fd_ebus_dma.regs = (void __iomem *) op->resource[1].start; if (!sun_pci_fd_ebus_dma.regs) - return 0; + goto out_put_node; sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER | EBUS_DMA_FLAG_TCI_DISABLE); @@ -619,7 +620,7 @@ static unsigned long __init sun_floppy_init(void) sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ; strcpy(sun_pci_fd_ebus_dma.name, "floppy"); if (ebus_dma_register(&sun_pci_fd_ebus_dma)) - return 0; + goto out_put_node; /* XXX ioremap */ sun_fdc = (struct sun_flpy_controller *) op->resource[0].start; @@ -686,7 +687,7 @@ static unsigned long __init sun_floppy_init(void) } if (!config) - return sun_floppy_types[0]; + goto out_floppy; /* Enable PC-AT mode. */ ns87303_modify(config, ASC, 0, 0xc0); @@ -715,11 +716,11 @@ static unsigned long __init sun_floppy_init(void) } #endif /* PCI_FDC_SWAP_DRIVES */ - return sun_floppy_types[0]; + goto out_floppy; } prop = of_get_property(op->dev.of_node, "status", NULL); if (prop && !strncmp(state, "disabled", 8)) - return 0; + goto out_put_node; /* * We cannot do of_ioremap here: it does request_region, @@ -734,7 +735,7 @@ static unsigned long __init sun_floppy_init(void) /* Last minute sanity check... */ if (sbus_readb(&sun_fdc->status1_82077) == 0xff) { sun_fdc = (struct sun_flpy_controller *)-1; - return 0; + goto out_put_node; } sun_fdops.fd_inb = sun_82077_fd_inb; @@ -760,7 +761,13 @@ static unsigned long __init sun_floppy_init(void) sun_floppy_types[0] = 4; sun_floppy_types[1] = 0; +out_floppy: + of_node_put(ebus_dp); return sun_floppy_types[0]; + +out_put_node: + of_node_put(ebus_dp); + return 0; } #define EXTRA_FLOPPY_PARAMS -- 2.25.1