History

livepatch: Remove duplicated code for early initialization

kobject_init() call added one more operation that has to be done when doing the early initialization of both static and dynamic livepatch structures. It would have been easier when the early initialization code was not duplicated. Let's deduplicate it for future generations of livepatching hackers. The patch does not change the existing behavior.

Petr Mladek committed 7 years ago

Commit f68d67c1 parent 4d141ab1 file · +26 −16Browse files

Unified · Split

kernel/livepatch/core.c+26−16
@@ -426,10 +426,13 @@ static void klp_free_object_dynamic(struct klp_object *obj) · 425 unmodified lines
426 kfree(obj);426 kfree(obj);
427}427}
428 428
429static struct kobj_type klp_ktype_object;429static void klp_init_func_early(struct klp_object *obj,
430static struct kobj_type klp_ktype_func;430 struct klp_func *func);
431static void klp_init_object_early(struct klp_patch *patch,
432 struct klp_object *obj);
431 433
432static struct klp_object *klp_alloc_object_dynamic(const char *name)434static 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) · 9 unmodified lines
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, · 22 unmodified lines
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 are482 * 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, · 13 unmodified lines
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, · 4 unmodified lines
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) · 284 unmodified lines
802 return ret;800 return ret;
803}801}
804 802
803static 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
810static 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
805static int klp_init_patch_early(struct klp_patch *patch)818static 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) · 14 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t