[3/4] kobject: validate ktype release function during add
Commit Message
Validating the ktype during cleanup is suboptimal.
Many kobjects are only destroyed during shutdown which makes it hard to
observe the messages.
Instead perform the validation when the object is added.
Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Link: https://lore.kernel.org/lkml/60b2b66c-22c9-1d38-ed1c-7b7d95e32720@alu.unizg.hr/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
lib/kobject.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On Sat, Mar 11, 2023 at 03:14:48AM +0000, Thomas Weißschuh wrote:
> Validating the ktype during cleanup is suboptimal.
> Many kobjects are only destroyed during shutdown which makes it hard to
> observe the messages.
>
> Instead perform the validation when the object is added.
As much as I would like to do this, it will cause way too many
false-positives at this point in time, sorry.
Yes, kobjects should always have a release function, but for some, they
are static structures and so do not have them, which is why we only
report the problem when the object is going away as that is when it
matters.
So if you fix up all the in-kernel static kobjects first, then we can
take this type of change, sorry.
Your first 2 are great though, I'll go queue them up next week, thanks
for the cleanups there.
greg k-h
@@ -215,6 +215,10 @@ static int kobject_add_internal(struct kobject *kobj)
return -EINVAL;
}
+ if (kobj->ktype && !kobj->ktype->release)
+ pr_debug("'%s' (%p): does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n",
+ kobject_name(kobj), kobj);
+
parent = kobject_get(kobj->parent);
/* join kset if set, use it as parent if we do not already have one */
@@ -663,10 +667,6 @@ static void kobject_cleanup(struct kobject *kobj)
pr_debug("'%s' (%p): %s, parent %p\n",
kobject_name(kobj), kobj, __func__, kobj->parent);
- if (t && !t->release)
- pr_debug("'%s' (%p): does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n",
- kobject_name(kobj), kobj);
-
/* remove from sysfs if the caller did not do it */
if (kobj->state_in_sysfs) {
pr_debug("'%s' (%p): auto cleanup kobject_del\n",