Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1263170
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 3/3] staging: lustre: Less function calls in class_register_type() after error detection |
| Date | 2015-11-05 13:30 +0100 |
| Message-ID | <qrrPX-6Ed-3@gated-at.bofh.it> (permalink) |
| References | (13 earlier) <mSsDN-4wa-61@gated-at.bofh.it> <mSsDN-4wa-63@gated-at.bofh.it> <mSsDN-4wa-65@gated-at.bofh.it> <mSsDN-4wa-33@gated-at.bofh.it> <qrrGi-6Az-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 5 Nov 2015 12:48:58 +0100
The functions "kfree" and "kobject_put" were called in a few cases by the
function "class_register_type" during error handling even if the passed
variable contained a null pointer.
This implementation detail could be improved by the adjustment of
jump targets.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/lustre/lustre/obdclass/genops.c | 26 +++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
index acb86f0..4d99a39 100644
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -171,13 +171,16 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
return rc;
type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
+ if (!type->typ_dt_ops)
+ goto free_type;
+
type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS);
- type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);
+ if (!type->typ_md_ops)
+ goto free_dt_ops;
- if (!type->typ_dt_ops ||
- !type->typ_md_ops ||
- !type->typ_name)
- goto failed;
+ type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);
+ if (!type->typ_name)
+ goto free_md_ops;
*(type->typ_dt_ops) = *dt_ops;
/* md_ops is optional */
@@ -193,20 +196,20 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
rc = type->typ_debugfs_entry ? PTR_ERR(type->typ_debugfs_entry)
: -ENOMEM;
type->typ_debugfs_entry = NULL;
- goto failed;
+ goto free_name;
}
type->typ_kobj = kobject_create_and_add(type->typ_name, lustre_kobj);
if (!type->typ_kobj) {
rc = -ENOMEM;
- goto failed;
+ goto free_name;
}
if (ldt != NULL) {
type->typ_lu = ldt;
rc = lu_device_type_init(ldt);
if (rc != 0)
- goto failed;
+ goto put_object;
}
spin_lock(&obd_types_lock);
@@ -214,12 +217,15 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
spin_unlock(&obd_types_lock);
return 0;
-
- failed:
+put_object:
kobject_put(type->typ_kobj);
+free_name:
kfree(type->typ_name);
+free_md_ops:
kfree(type->typ_md_ops);
+free_dt_ops:
kfree(type->typ_dt_ops);
+free_type:
kfree(type);
return rc;
}
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 0/3] staging: lustre: Deletion of some unnecessary checks SF Markus Elfring <elfring@users.sourceforge.net> - 2015-11-05 13:20 +0100
[PATCH 2/3] staging: lustre: Delete an unnecessary variable initialisation in class_register_type() SF Markus Elfring <elfring@users.sourceforge.net> - 2015-11-05 13:20 +0100
Re: [PATCH 2/3] staging: lustre: Delete an unnecessary variable initialisation in class_register_type() Dan Carpenter <dan.carpenter@oracle.com> - 2015-11-05 14:00 +0100
[PATCH 1/3] staging: lustre: Delete unnecessary checks before two function calls SF Markus Elfring <elfring@users.sourceforge.net> - 2015-11-05 13:20 +0100
Re: [PATCH 1/3] staging: lustre: Delete unnecessary checks before two function calls Dan Carpenter <dan.carpenter@oracle.com> - 2015-11-05 14:00 +0100
[PATCH 3/3] staging: lustre: Less function calls in class_register_type() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2015-11-05 13:30 +0100
csiph-web