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
426426 kfree(obj);
427427 }
428428
429−static struct kobj_type klp_ktype_object;
430−static struct kobj_type klp_ktype_func;
429+static void klp_init_func_early(struct klp_object *obj,
430+ struct klp_func *func);
431+static void klp_init_object_early(struct klp_patch *patch,
432+ struct klp_object *obj);
431433
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)
433436 {
434437 struct klp_object *obj;
435438
@@ -445,8 +448,7 @@ static struct klp_object *klp_alloc_object_dynamic(const char *name) · 9 unmodified lines
445448 }
446449 }
447450
448− INIT_LIST_HEAD(&obj->func_list);
449− kobject_init(&obj->kobj, &klp_ktype_object);
451+ klp_init_object_early(patch, obj);
450452 obj->dynamic = true;
451453
452454 return obj;
@@ -475,7 +477,7 @@ static struct klp_func *klp_alloc_func_nop(struct klp_func *old_func, · 22 unmodified lines
475477 }
476478 }
477479
478− kobject_init(&func->kobj, &klp_ktype_func);
480+ klp_init_func_early(obj, func);
479481 /*
480482 * func->new_func is same as func->old_func. These addresses are
481483 * 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
495497 obj = klp_find_object(patch, old_obj);
496498
497499 if (!obj) {
498− obj = klp_alloc_object_dynamic(old_obj->name);
500+ obj = klp_alloc_object_dynamic(old_obj->name, patch);
499501 if (!obj)
500502 return -ENOMEM;
501−
502− list_add_tail(&obj->node, &patch->obj_list);
503503 }
504504
505505 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
510510 func = klp_alloc_func_nop(old_func, obj);
511511 if (!func)
512512 return -ENOMEM;
513−
514− list_add_tail(&func->node, &obj->func_list);
515513 }
516514
517515 return 0;
@@ -802,6 +800,21 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj) · 284 unmodified lines
802800 return ret;
803801 }
804802
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+
805818 static int klp_init_patch_early(struct klp_patch *patch)
806819 {
807820 struct klp_object *obj;
@@ -822,13 +835,10 @@ static int klp_init_patch_early(struct klp_patch *patch) · 14 unmodified lines
822835 if (!obj->funcs)
823836 return -EINVAL;
824837
825− INIT_LIST_HEAD(&obj->func_list);
826− kobject_init(&obj->kobj, &klp_ktype_object);
827− list_add_tail(&obj->node, &patch->obj_list);
838+ klp_init_object_early(patch, obj);
828839
829840 klp_for_each_func_static(obj, func) {
830− kobject_init(&func->kobj, &klp_ktype_func);
831− list_add_tail(&func->node, &obj->func_list);
841+ klp_init_func_early(obj, func);
832842 }
833843 }
834844

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