Acked-by: Fernando Guzman Lugo <x0095...@ti.com>

-----Original Message-----
From: Felipe Balbi [mailto:felipe.ba...@nokia.com] 
Sent: Friday, August 21, 2009 5:24 AM
To: Hiroshi DOYU
Cc: Ameya Palande; Guzman Lugo, Fernando; Linux OMAP Mailing List; Felipe Balbi
Subject: [DSPBRIGDE PATCH 6/6] dsp: bridge: beautify erro path

... and get rid of a possible memory leak.

in case of error while adding the chardev, probe()
would not kfree() bridge_device.

Signed-off-by: Felipe Balbi <felipe.ba...@nokia.com>
---
 drivers/dsp/bridge/rmgr/drv_interface.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/dsp/bridge/rmgr/drv_interface.c 
b/drivers/dsp/bridge/rmgr/drv_interface.c
index 559d14a..c37c5a0 100755
--- a/drivers/dsp/bridge/rmgr/drv_interface.c
+++ b/drivers/dsp/bridge/rmgr/drv_interface.c
@@ -324,7 +324,7 @@ static int __init bridge_init(void)
        if (result < 0) {
                GT_1trace(driverTrace, GT_7CLASS, "bridge_init: "
                                "Can't get Major %d \n", driver_major);
-               return result;
+               goto err1;
        }
 
        driver_major = MAJOR(dev);
@@ -332,19 +332,17 @@ static int __init bridge_init(void)
        bridge_device = kmalloc(sizeof(struct bridge_dev), GFP_KERNEL);
        if (!bridge_device) {
                result = -ENOMEM;
-               unregister_chrdev_region(dev, 1);
-               return result;
+               goto err2;
        }
        cdev_init(&bridge_device->cdev, &bridge_fops);
        bridge_device->cdev.owner = THIS_MODULE;
        bridge_device->cdev.ops = &bridge_fops;
 
        status = cdev_add(&bridge_device->cdev, dev, 1);
-
        if (status) {
                GT_0trace(driverTrace, GT_7CLASS,
                                "Failed to add the bridge device \n");
-               return status;
+               goto err3;
        }
 
        /* udev support */
@@ -474,7 +472,17 @@ static int __init bridge_init(void)
        DBC_Assert(status == 0);
        DBC_Assert(DSP_SUCCEEDED(initStatus));
        GT_0trace(driverTrace, GT_ENTER, " <- driver_init\n");
-       return status;
+
+       return 0;
+
+err3:
+       kfree(bridge_device);
+
+err2:
+       unregister_chrdev_region(dev, 1);
+
+err1:
+       return result;
 }
 
 /*  This function is invoked during unlinking of the bridge module from the
-- 
1.6.3.3.385.g60647


--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to