diff mbox series

[02/11] kset: add null pointer check in kset_put()

Message ID 20221021022102.2231464-3-yangyingliang@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix memory leak while kset_register() fails | expand

Commit Message

Yang Yingliang Oct. 21, 2022, 2:20 a.m. UTC
kset_put() can be called from drivers, add null pointer
check to make it more robust.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
 include/linux/kobject.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 57fb972fea05..e81de8ba41a2 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -195,7 +195,8 @@  static inline struct kset *kset_get(struct kset *k)
 static inline void kset_put(struct kset *k)
-	kobject_put(&k->kobj);
+	if (k)
+		kobject_put(&k->kobj);
 static inline const struct kobj_type *get_ktype(struct kobject *kobj)