Skip to content

Commit cad706d

Browse files
mirabJiri Kosina
authored andcommitted
livepatch: make kobject in klp_object statically allocated
Make kobj variable (of type struct kobject) statically allocated in klp_object structure. It will allow us to move in the func-object-patch hierarchy through kobject links. The only reason to have it dynamic was to not have empty release callback in the code. However we have empty callbacks for function and patch in the code now, so it is no longer valid and the advantage of static allocation is clear. Signed-off-by: Miroslav Benes <mbenes@suse.cz> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 36e505c commit cad706d

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎include/linux/livepatch.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct klp_object {
9999
struct klp_func *funcs;
100100

101101
/* internal */
102-
struct kobject *kobj;
102+
struct kobject kobj;
103103
struct module *mod;
104104
enum klp_state state;
105105
};

‎kernel/livepatch/core.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,15 @@ static struct kobj_type klp_ktype_patch = {
651651
.default_attrs = klp_patch_attrs,
652652
};
653653

654+
static void klp_kobj_release_object(struct kobject *kobj)
655+
{
656+
}
657+
658+
static struct kobj_type klp_ktype_object = {
659+
.release = klp_kobj_release_object,
660+
.sysfs_ops = &kobj_sysfs_ops,
661+
};
662+
654663
static void klp_kobj_release_func(struct kobject *kobj)
655664
{
656665
}
@@ -695,7 +704,7 @@ static void klp_free_objects_limited(struct klp_patch *patch,
695704

696705
for (obj = patch->objs; obj->funcs && obj != limit; obj++) {
697706
klp_free_funcs_limited(obj, NULL);
698-
kobject_put(obj->kobj);
707+
kobject_put(&obj->kobj);
699708
}
700709
}
701710

@@ -713,7 +722,7 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
713722
func->state = KLP_DISABLED;
714723

715724
return kobject_init_and_add(&func->kobj, &klp_ktype_func,
716-
obj->kobj, "%s", func->old_name);
725+
&obj->kobj, "%s", func->old_name);
717726
}
718727

719728
/* parts of the initialization that is done only when the object is loaded */
@@ -753,9 +762,10 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
753762
klp_find_object_module(obj);
754763

755764
name = klp_is_module(obj) ? obj->name : "vmlinux";
756-
obj->kobj = kobject_create_and_add(name, &patch->kobj);
757-
if (!obj->kobj)
758-
return -ENOMEM;
765+
ret = kobject_init_and_add(&obj->kobj, &klp_ktype_object,
766+
&patch->kobj, "%s", name);
767+
if (ret)
768+
return ret;
759769

760770
for (func = obj->funcs; func->old_name; func++) {
761771
ret = klp_init_func(obj, func);
@@ -773,7 +783,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
773783

774784
free:
775785
klp_free_funcs_limited(obj, func);
776-
kobject_put(obj->kobj);
786+
kobject_put(&obj->kobj);
777787
return ret;
778788
}
779789

0 commit comments

Comments
 (0)