From: Lin Yi teroincn@163.com
mainline inclusion from mainline-v5.3-rc1 commit 122f8ec7b78e category: bugfix bugzilla: 18462 CVE: NA
-------------------------------------------------
the kobj refcount increased by kobject_get should be released before error return, otherwise lead to a memory leak.
Signed-off-by: Lin Yi teroincn@163.com Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: Li Heng liheng40@huawei.com Reviewed-by: Xie XiuQi xiexiuqi@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- lib/kobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/kobject.c b/lib/kobject.c index 97d86dc17c42..c82b88b2e860 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -478,8 +478,10 @@ int kobject_rename(struct kobject *kobj, const char *new_name) kobj = kobject_get(kobj); if (!kobj) return -EINVAL; - if (!kobj->parent) + if (!kobj->parent) { + kobject_put(kobj); return -EINVAL; + }
devpath = kobject_get_path(kobj, GFP_KERNEL); if (!devpath) {