aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiroslav Benes <mbenes@suse.cz>2015-05-19 06:01:18 -0400
committerJiri Kosina <jkosina@suse.cz>2015-05-19 17:56:41 -0400
commitcad706df7e4a00a595f2662f32c0fc174aa4e61f (patch)
treecd289c2f2478ad3c269b00bf22d2bd39818d0df6
parent36e505c16e610403c110bab76a95cbfa0436a928 (diff)
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>
-rw-r--r--include/linux/livepatch.h2
-rw-r--r--kernel/livepatch/core.c22
2 files changed, 17 insertions, 7 deletions
diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index ee6dbb39a809..fe45f2f02c8d 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -99,7 +99,7 @@ struct klp_object {
99 struct klp_func *funcs; 99 struct klp_func *funcs;
100 100
101 /* internal */ 101 /* internal */
102 struct kobject *kobj; 102 struct kobject kobj;
103 struct module *mod; 103 struct module *mod;
104 enum klp_state state; 104 enum klp_state state;
105}; 105};
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index c03c04637ec6..e997782362c3 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -651,6 +651,15 @@ static struct kobj_type klp_ktype_patch = {
651 .default_attrs = klp_patch_attrs, 651 .default_attrs = klp_patch_attrs,
652}; 652};
653 653
654static void klp_kobj_release_object(struct kobject *kobj)
655{
656}
657
658static struct kobj_type klp_ktype_object = {
659 .release = klp_kobj_release_object,
660 .sysfs_ops = &kobj_sysfs_ops,
661};
662
654static void klp_kobj_release_func(struct kobject *kobj) 663static void klp_kobj_release_func(struct kobject *kobj)
655{ 664{
656} 665}
@@ -695,7 +704,7 @@ static void klp_free_objects_limited(struct klp_patch *patch,
695 704
696 for (obj = patch->objs; obj->funcs && obj != limit; obj++) { 705 for (obj = patch->objs; obj->funcs && obj != limit; obj++) {
697 klp_free_funcs_limited(obj, NULL); 706 klp_free_funcs_limited(obj, NULL);
698 kobject_put(obj->kobj); 707 kobject_put(&obj->kobj);
699 } 708 }
700} 709}
701 710
@@ -713,7 +722,7 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
713 func->state = KLP_DISABLED; 722 func->state = KLP_DISABLED;
714 723
715 return kobject_init_and_add(&func->kobj, &klp_ktype_func, 724 return kobject_init_and_add(&func->kobj, &klp_ktype_func,
716 obj->kobj, "%s", func->old_name); 725 &obj->kobj, "%s", func->old_name);
717} 726}
718 727
719/* parts of the initialization that is done only when the object is loaded */ 728/* 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)
753 klp_find_object_module(obj); 762 klp_find_object_module(obj);
754 763
755 name = klp_is_module(obj) ? obj->name : "vmlinux"; 764 name = klp_is_module(obj) ? obj->name : "vmlinux";
756 obj->kobj = kobject_create_and_add(name, &patch->kobj); 765 ret = kobject_init_and_add(&obj->kobj, &klp_ktype_object,
757 if (!obj->kobj) 766 &patch->kobj, "%s", name);
758 return -ENOMEM; 767 if (ret)
768 return ret;
759 769
760 for (func = obj->funcs; func->old_name; func++) { 770 for (func = obj->funcs; func->old_name; func++) {
761 ret = klp_init_func(obj, func); 771 ret = klp_init_func(obj, func);
@@ -773,7 +783,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
773 783
774free: 784free:
775 klp_free_funcs_limited(obj, func); 785 klp_free_funcs_limited(obj, func);
776 kobject_put(obj->kobj); 786 kobject_put(&obj->kobj);
777 return ret; 787 return ret;
778} 788}
779 789