[PATCH] ocfs2: need to check return value from kobject_set_name()

From: yu kuai
Date: Tue Aug 13 2019 - 08:44:22 EST


Since kobject_set_name() might return an error, the return value need to
be checked, otherwise there will be a warn:

mlog_sys_init
kset_register
kobject_add_internal
if (!kobj->name || !kobj->name[0]) {
WARN(...);
return -EINVAL;
}

Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Signed-off-by: yu kuai <yukuai3@xxxxxxxxxx>
---
fs/ocfs2/cluster/masklog.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index d331c23..4fcef46 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -178,7 +178,8 @@ int mlog_sys_init(struct kset *o2cb_kset)
}
mlog_attr_ptrs[i] = NULL;

- kobject_set_name(&mlog_kset.kobj, "logmask");
+ if (!kobject_set_name(&mlog_kset.kobj, "logmask"))
+ return -EINVAL;
mlog_kset.kobj.kset = o2cb_kset;
return kset_register(&mlog_kset);
}
--
2.7.4