diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2023-01-20 22:46:57 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-01-23 16:47:18 +0300 |
commit | 0b2a1a3938aad80fb19cb53cbbd4679eeb37e3a8 (patch) | |
tree | d3b4fd0b0545eced739dc8a70bdd76f1abdec4f4 /drivers/base/class.c | |
parent | f89fd04323f755e7437a0113d986812c3fffe03d (diff) | |
download | linux-0b2a1a3938aad80fb19cb53cbbd4679eeb37e3a8.tar.xz |
driver core: class: Clear private pointer on registration failures
Clear the class private pointer if __class_register() fails for it, so
as to allow its users to verify that the class is usable by checking
the value of that pointer.
For consistency, clear that pointer before freeing the object pointed
to by it in class_release().
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/4463268.LvFx2qVVIh@kreacher
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r-- | drivers/base/class.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 3366da9c3ff6..a38b0d7d681d 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -53,6 +53,8 @@ static void class_release(struct kobject *kobj) pr_debug("class '%s': release.\n", class->name); + class->p = NULL; + if (class->class_release) class->class_release(class); else @@ -186,17 +188,21 @@ int __class_register(struct class *cls, struct lock_class_key *key) cls->p = cp; error = kset_register(&cp->subsys); - if (error) { - kfree(cp); - return error; - } + if (error) + goto err_out; + error = class_add_groups(class_get(cls), cls->class_groups); class_put(cls); if (error) { kobject_del(&cp->subsys.kobj); kfree_const(cp->subsys.kobj.name); - kfree(cp); + goto err_out; } + return 0; + +err_out: + kfree(cp); + cls->p = NULL; return error; } EXPORT_SYMBOL_GPL(__class_register); |