From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH v1 1/2] driver core: class: Clear private pointer on registration failures
Date: Fri, 20 Jan 2023 20:46:57 +0100 [thread overview]
Message-ID: <4463268.LvFx2qVVIh@kreacher> (raw)
In-Reply-To: <5905717.lOV4Wx5bFT@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
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>
---
drivers/base/class.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
Index: linux-pm/drivers/base/class.c
===================================================================
--- linux-pm.orig/drivers/base/class.c
+++ linux-pm/drivers/base/class.c
@@ -53,6 +53,8 @@ static void class_release(struct kobject
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,
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);
next prev parent reply other threads:[~2023-01-20 19:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 19:45 [PATCH v1 0/2] driver core/thermal: Fail registration of thermal object when thermal_class is not registered Rafael J. Wysocki
2023-01-20 19:46 ` Rafael J. Wysocki [this message]
2023-01-20 22:43 ` [PATCH v1 1/2] driver core: class: Clear private pointer on registration failures Daniel Lezcano
2023-01-20 19:48 ` [PATCH v1 2/2] thermal: Fail object registration if thermal class is not registered Rafael J. Wysocki
2023-01-20 22:43 ` Daniel Lezcano
2023-01-21 7:40 ` Greg Kroah-Hartman
2023-01-23 20:16 ` Rafael J. Wysocki
2023-01-24 6:03 ` Greg Kroah-Hartman
2023-01-24 13:57 ` Rafael J. Wysocki
2023-01-24 17:03 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4463268.LvFx2qVVIh@kreacher \
--to=rjw@rjwysocki.net \
--cc=daniel.lezcano@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rui.zhang@intel.com \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox