Whamcloud - gitweb
LU-2275: obdclass: Proper error cleaup for class_newdev
authorOleg Drokin <green@whamcloud.com>
Mon, 5 Nov 2012 05:24:18 +0000 (00:24 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 7 Nov 2012 02:40:52 +0000 (21:40 -0500)
class_newdev did not have a proper cleanup for the case of no more
obd devices and used to leak obdtype reference and some memory
in such a case.
This patch fixes the issue.

Change-Id: I6b683f914f5cbcd21ef414fe470ccc88c39c4deb
Signed-off-by: Oleg Drokin <green@whamcloud.com
Reviewed-on: http://review.whamcloud.com/4460
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Bobi Jam <bobijam@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/genops.c

index 6fd2624..316c9f9 100644 (file)
@@ -300,10 +300,9 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
         }
 
         newdev = obd_device_alloc();
         }
 
         newdev = obd_device_alloc();
-        if (newdev == NULL) {
-                class_put_type(type);
-                RETURN(ERR_PTR(-ENOMEM));
-        }
+       if (newdev == NULL)
+               GOTO(out_type, result = ERR_PTR(-ENOMEM));
+
         LASSERT(newdev->obd_magic == OBD_DEVICE_MAGIC);
 
         cfs_write_lock(&obd_dev_lock);
         LASSERT(newdev->obd_magic == OBD_DEVICE_MAGIC);
 
         cfs_write_lock(&obd_dev_lock);
@@ -343,17 +342,21 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
         if (result == NULL && i >= class_devno_max()) {
                 CERROR("all %u OBD devices used, increase MAX_OBD_DEVICES\n",
                        class_devno_max());
         if (result == NULL && i >= class_devno_max()) {
                 CERROR("all %u OBD devices used, increase MAX_OBD_DEVICES\n",
                        class_devno_max());
-                RETURN(ERR_PTR(-EOVERFLOW));
+               GOTO(out, result = ERR_PTR(-EOVERFLOW));
         }
 
         }
 
-        if (IS_ERR(result)) {
-                obd_device_free(newdev);
-                class_put_type(type);
-        } else {
-                CDEBUG(D_IOCTL, "Adding new device %s (%p)\n",
-                       result->obd_name, result);
-        }
-        RETURN(result);
+       if (IS_ERR(result))
+               GOTO(out, result);
+
+       CDEBUG(D_IOCTL, "Adding new device %s (%p)\n",
+              result->obd_name, result);
+
+       RETURN(result);
+out:
+       obd_device_free(newdev);
+out_type:
+       class_put_type(type);
+       return result;
 }
 
 void class_release_dev(struct obd_device *obd)
 }
 
 void class_release_dev(struct obd_device *obd)