[PATCH v2 1/2] sparc/of: fix possible memory leak in scan_one_device()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically,
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.

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
---
 arch/sparc/kernel/of_device_32.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
index 4ebf51e6e78e..c93f5077a4cc 100644
--- a/arch/sparc/kernel/of_device_32.c
+++ b/arch/sparc/kernel/of_device_32.c
@@ -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;
 	}
 
-- 
2.25.1




[Index of Archives]     [Kernel Development]     [DCCP]     [Linux ARM Development]     [Linux]     [Photo]     [Yosemite Help]     [Linux ARM Kernel]     [Linux SCSI]     [Linux x86_64]     [Linux Hams]

  Powered by Linux