sparc/of: fix possible memory leak in scan_one_device()
PATCH 1/2 sparc/of: fix possible memory leak in scan_one_device()
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.
--- arch/sparc/kernel/of_device_32.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/sparc/kernel/of_device_32.c +7 -1
@@ -185,6 +185,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,
@@ -384,10 +389,11 @@ static struct platform_device * __init scan_one_device(struct device_node *dp, 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 ; }
Signature · 1 line
2.25.1
PATCH 2/2 sparc64/of: fix possible memory leak in scan_one_device()
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.
--- arch/sparc/kernel/of_device_64.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/sparc/kernel/of_device_64.c +7 -1
@@ -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 ; }
Signature · 1 line
2.25.1