From: Oleg Drokin Date: Mon, 5 Nov 2012 05:24:18 +0000 (-0500) Subject: LU-2275: obdclass: Proper error cleaup for class_newdev X-Git-Tag: 2.3.55~25 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3b41ac8f3feee5252a55553ad795545cfc8636f6 LU-2275: obdclass: Proper error cleaup for class_newdev 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 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin --- diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 6fd2624..316c9f9 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -300,10 +300,9 @@ struct obd_device *class_newdev(const char *type_name, const char *name) } 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); @@ -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()); - 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)