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

From: Yang Yingliang
Date: Thu Oct 20 2022 - 22:22:47 EST


kset_put() can be called from drivers, add null pointer
check to make it more robust.

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

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)
--
2.25.1