diff options
Diffstat (limited to 'kernel/livepatch/core.c')
-rw-r--r-- | kernel/livepatch/core.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 42385f23252a..f12c0eabd843 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c | |||
@@ -426,10 +426,13 @@ static void klp_free_object_dynamic(struct klp_object *obj) | |||
426 | kfree(obj); | 426 | kfree(obj); |
427 | } | 427 | } |
428 | 428 | ||
429 | static struct kobj_type klp_ktype_object; | 429 | static void klp_init_func_early(struct klp_object *obj, |
430 | static struct kobj_type klp_ktype_func; | 430 | struct klp_func *func); |
431 | static void klp_init_object_early(struct klp_patch *patch, | ||
432 | struct klp_object *obj); | ||
431 | 433 | ||
432 | static struct klp_object *klp_alloc_object_dynamic(const char *name) | 434 | static struct klp_object *klp_alloc_object_dynamic(const char *name, |
435 | struct klp_patch *patch) | ||
433 | { | 436 | { |
434 | struct klp_object *obj; | 437 | struct klp_object *obj; |
435 | 438 | ||
@@ -445,8 +448,7 @@ static struct klp_object *klp_alloc_object_dynamic(const char *name) | |||
445 | } | 448 | } |
446 | } | 449 | } |
447 | 450 | ||
448 | INIT_LIST_HEAD(&obj->func_list); | 451 | klp_init_object_early(patch, obj); |
449 | kobject_init(&obj->kobj, &klp_ktype_object); | ||
450 | obj->dynamic = true; | 452 | obj->dynamic = true; |
451 | 453 | ||
452 | return obj; | 454 | return obj; |
@@ -475,7 +477,7 @@ static struct klp_func *klp_alloc_func_nop(struct klp_func *old_func, | |||
475 | } | 477 | } |
476 | } | 478 | } |
477 | 479 | ||
478 | kobject_init(&func->kobj, &klp_ktype_func); | 480 | klp_init_func_early(obj, func); |
479 | /* | 481 | /* |
480 | * func->new_func is same as func->old_func. These addresses are | 482 | * func->new_func is same as func->old_func. These addresses are |
481 | * set when the object is loaded, see klp_init_object_loaded(). | 483 | * set when the object is loaded, see klp_init_object_loaded(). |
@@ -495,11 +497,9 @@ static int klp_add_object_nops(struct klp_patch *patch, | |||
495 | obj = klp_find_object(patch, old_obj); | 497 | obj = klp_find_object(patch, old_obj); |
496 | 498 | ||
497 | if (!obj) { | 499 | if (!obj) { |
498 | obj = klp_alloc_object_dynamic(old_obj->name); | 500 | obj = klp_alloc_object_dynamic(old_obj->name, patch); |
499 | if (!obj) | 501 | if (!obj) |
500 | return -ENOMEM; | 502 | return -ENOMEM; |
501 | |||
502 | list_add_tail(&obj->node, &patch->obj_list); | ||
503 | } | 503 | } |
504 | 504 | ||
505 | klp_for_each_func(old_obj, old_func) { | 505 | klp_for_each_func(old_obj, old_func) { |
@@ -510,8 +510,6 @@ static int klp_add_object_nops(struct klp_patch *patch, | |||
510 | func = klp_alloc_func_nop(old_func, obj); | 510 | func = klp_alloc_func_nop(old_func, obj); |
511 | if (!func) | 511 | if (!func) |
512 | return -ENOMEM; | 512 | return -ENOMEM; |
513 | |||
514 | list_add_tail(&func->node, &obj->func_list); | ||
515 | } | 513 | } |
516 | 514 | ||
517 | return 0; | 515 | return 0; |
@@ -802,6 +800,21 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj) | |||
802 | return ret; | 800 | return ret; |
803 | } | 801 | } |
804 | 802 | ||
803 | static void klp_init_func_early(struct klp_object *obj, | ||
804 | struct klp_func *func) | ||
805 | { | ||
806 | kobject_init(&func->kobj, &klp_ktype_func); | ||
807 | list_add_tail(&func->node, &obj->func_list); | ||
808 | } | ||
809 | |||
810 | static void klp_init_object_early(struct klp_patch *patch, | ||
811 | struct klp_object *obj) | ||
812 | { | ||
813 | INIT_LIST_HEAD(&obj->func_list); | ||
814 | kobject_init(&obj->kobj, &klp_ktype_object); | ||
815 | list_add_tail(&obj->node, &patch->obj_list); | ||
816 | } | ||
817 | |||
805 | static int klp_init_patch_early(struct klp_patch *patch) | 818 | static int klp_init_patch_early(struct klp_patch *patch) |
806 | { | 819 | { |
807 | struct klp_object *obj; | 820 | struct klp_object *obj; |
@@ -822,13 +835,10 @@ static int klp_init_patch_early(struct klp_patch *patch) | |||
822 | if (!obj->funcs) | 835 | if (!obj->funcs) |
823 | return -EINVAL; | 836 | return -EINVAL; |
824 | 837 | ||
825 | INIT_LIST_HEAD(&obj->func_list); | 838 | klp_init_object_early(patch, obj); |
826 | kobject_init(&obj->kobj, &klp_ktype_object); | ||
827 | list_add_tail(&obj->node, &patch->obj_list); | ||
828 | 839 | ||
829 | klp_for_each_func_static(obj, func) { | 840 | klp_for_each_func_static(obj, func) { |
830 | kobject_init(&func->kobj, &klp_ktype_func); | 841 | klp_init_func_early(obj, func); |
831 | list_add_tail(&func->node, &obj->func_list); | ||
832 | } | 842 | } |
833 | } | 843 | } |
834 | 844 | ||