[4/4] kobject: upgrade log of missing release func to warn

Message ID 20230311-kobject-warning-v1-4-1ebba4f71fb5@weissschuh.net
State New
Headers
Series kobject: properly warn on missing release function |

Commit Message

Thomas Weißschuh March 11, 2023, 3:14 a.m. UTC
  The documentation is outspoken in its requirement for a release()
function. Documentation/core-api/kobject.rst:

  One important point cannot be overstated: every kobject must have a
  release() method, and the kobject must persist (in a consistent state)
  until that method is called. If these constraints are not met, the code is
  flawed. Note that the kernel will warn you if you forget to provide a
  release() method.  Do not try to get rid of this warning by providing an
  "empty" release function.

So adapt the logging to actually provide the promised warning.

At the moment there are still kobjects that do not have a release()
function, notably integrity_ktype and acpi_hotplug_profile_ktype.
Therefore leave it at pr_warn().

When the remaining cases are fixed the message could be upgraded to
pr_err() and/or an -EINVAL could be returned.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 lib/kobject.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Patch

diff --git a/lib/kobject.c b/lib/kobject.c
index 68ff8a48b784..8723f477095e 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -215,9 +215,11 @@  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);
+	if (kobj->ktype && !kobj->ktype->release) {
+		pr_warn("'%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);
+		dump_stack_lvl(KERN_WARNING);
+	}
 
 	parent = kobject_get(kobj->parent);