]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
livepatch: make kobject in klp_object statically allocated
authorMiroslav Benes <mbenes@suse.cz>
Tue, 19 May 2015 10:01:18 +0000 (12:01 +0200)
committerJiri Kosina <jkosina@suse.cz>
Tue, 19 May 2015 21:56:41 +0000 (23:56 +0200)
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>
include/linux/livepatch.h
kernel/livepatch/core.c

index ee6dbb39a809811ca6aa563ea125fc9bb0af4756..fe45f2f02c8df6e97270aaeb8541510048894630 100644 (file)
@@ -99,7 +99,7 @@ struct klp_object {
        struct klp_func *funcs;
 
        /* internal */
-       struct kobject *kobj;
+       struct kobject kobj;
        struct module *mod;
        enum klp_state state;
 };
index c03c04637ec6d762aaee11574c9146d574090c6a..e997782362c3e8e1a19e024ace9c360bb3bd6779 100644 (file)
@@ -651,6 +651,15 @@ static struct kobj_type klp_ktype_patch = {
        .default_attrs = klp_patch_attrs,
 };
 
+static void klp_kobj_release_object(struct kobject *kobj)
+{
+}
+
+static struct kobj_type klp_ktype_object = {
+       .release = klp_kobj_release_object,
+       .sysfs_ops = &kobj_sysfs_ops,
+};
+
 static void klp_kobj_release_func(struct kobject *kobj)
 {
 }
@@ -695,7 +704,7 @@ static void klp_free_objects_limited(struct klp_patch *patch,
 
        for (obj = patch->objs; obj->funcs && obj != limit; obj++) {
                klp_free_funcs_limited(obj, NULL);
-               kobject_put(obj->kobj);
+               kobject_put(&obj->kobj);
        }
 }
 
@@ -713,7 +722,7 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
        func->state = KLP_DISABLED;
 
        return kobject_init_and_add(&func->kobj, &klp_ktype_func,
-                                   obj->kobj, "%s", func->old_name);
+                                   &obj->kobj, "%s", func->old_name);
 }
 
 /* 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)
        klp_find_object_module(obj);
 
        name = klp_is_module(obj) ? obj->name : "vmlinux";
-       obj->kobj = kobject_create_and_add(name, &patch->kobj);
-       if (!obj->kobj)
-               return -ENOMEM;
+       ret = kobject_init_and_add(&obj->kobj, &klp_ktype_object,
+                                  &patch->kobj, "%s", name);
+       if (ret)
+               return ret;
 
        for (func = obj->funcs; func->old_name; func++) {
                ret = klp_init_func(obj, func);
@@ -773,7 +783,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
 
 free:
        klp_free_funcs_limited(obj, func);
-       kobject_put(obj->kobj);
+       kobject_put(&obj->kobj);
        return ret;
 }