dev_set_name() in scan_one_device() allocates memory for name, it need be freed when of_device_register() fails, call put_device() to give up the reference that hold in device_initialize(), so that it can be freed in kobject_cleanup() when the refcount hit to 0. And add op_dev_release() to free platform device. Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx> --- arch/sparc/kernel/of_device_64.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/sparc/kernel/of_device_64.c b/arch/sparc/kernel/of_device_64.c index 5a9f86b1d4e7..7496c8af12a6 100644 --- a/arch/sparc/kernel/of_device_64.c +++ b/arch/sparc/kernel/of_device_64.c @@ -239,6 +239,11 @@ static struct of_bus *of_match_bus(struct device_node *np) return NULL; } +static void op_dev_release(struct device *dev) +{ + kfree(to_platform_device(dev)); +} + static int __init build_one_resource(struct device_node *parent, struct of_bus *bus, struct of_bus *pbus, @@ -677,10 +682,11 @@ static struct platform_device * __init scan_one_device(struct device_node *dp, dev_set_name(&op->dev, "%08x", dp->phandle); op->dev.coherent_dma_mask = DMA_BIT_MASK(32); op->dev.dma_mask = &op->dev.coherent_dma_mask; + op->dev.release = op_dev_release; if (of_device_register(op)) { printk("%pOF: Could not register of device.\n", dp); - kfree(op); + put_device(&op->dev); op = NULL; } -- 2.25.1