staging: vme: fix memory leak in vme_user_probe()
authorDaeseok Youn <daeseok.youn@gmail.com>
Wed, 26 Mar 2014 03:01:48 +0000 (12:01 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Apr 2014 21:46:43 +0000 (14:46 -0700)
If vme_master_request() returns NULL when it failed,
it need to free buffers for master.

And also removes unreachable code in vme_user_probe().

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vme/devices/vme_user.c

index 792792715673fe3e987c623f082c4c17c5ade5e5..ffb4eeefdddb37e5ae2447c6501b50e00e59f37f 100644 (file)
@@ -776,7 +776,8 @@ static int vme_user_probe(struct vme_dev *vdev)
                image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL);
                if (image[i].kern_buf == NULL) {
                        err = -ENOMEM;
-                       goto err_master_buf;
+                       vme_master_free(image[i].resource);
+                       goto err_master;
                }
        }
 
@@ -819,8 +820,6 @@ static int vme_user_probe(struct vme_dev *vdev)
 
        return 0;
 
-       /* Ensure counter set correcty to destroy all sysfs devices */
-       i = VME_DEVS;
 err_sysfs:
        while (i > 0) {
                i--;
@@ -830,12 +829,10 @@ err_sysfs:
 
        /* Ensure counter set correcty to unalloc all master windows */
        i = MASTER_MAX + 1;
-err_master_buf:
-       for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++)
-               kfree(image[i].kern_buf);
 err_master:
        while (i > MASTER_MINOR) {
                i--;
+               kfree(image[i].kern_buf);
                vme_master_free(image[i].resource);
        }