livepatch: Introduce klp_for_each_patch macro
authorPetr Mladek <pmladek@suse.com>
Mon, 4 Feb 2019 13:56:50 +0000 (14:56 +0100)
committerPetr Mladek <pmladek@suse.com>
Wed, 6 Feb 2019 09:49:30 +0000 (10:49 +0100)
There are already macros to iterate over struct klp_func and klp_object.

Add also klp_for_each_patch(). But make it internal because also
klp_patches list is internal.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
kernel/livepatch/core.c
kernel/livepatch/core.h
kernel/livepatch/transition.c

index 5fc98a1cc3c34799e26e755847a9ba90ee429a4c..4b7f55d9e89ce31ab06489b3a988a3c5c116ec2d 100644 (file)
@@ -554,7 +554,7 @@ static int klp_add_nops(struct klp_patch *patch)
        struct klp_patch *old_patch;
        struct klp_object *old_obj;
 
-       list_for_each_entry(old_patch, &klp_patches, list) {
+       klp_for_each_patch(old_patch) {
                klp_for_each_object(old_patch, old_obj) {
                        int err;
 
@@ -1089,7 +1089,7 @@ void klp_discard_replaced_patches(struct klp_patch *new_patch)
 {
        struct klp_patch *old_patch, *tmp_patch;
 
-       list_for_each_entry_safe(old_patch, tmp_patch, &klp_patches, list) {
+       klp_for_each_patch_safe(old_patch, tmp_patch) {
                if (old_patch == new_patch)
                        return;
 
@@ -1133,7 +1133,7 @@ static void klp_cleanup_module_patches_limited(struct module *mod,
        struct klp_patch *patch;
        struct klp_object *obj;
 
-       list_for_each_entry(patch, &klp_patches, list) {
+       klp_for_each_patch(patch) {
                if (patch == limit)
                        break;
 
@@ -1180,7 +1180,7 @@ int klp_module_coming(struct module *mod)
         */
        mod->klp_alive = true;
 
-       list_for_each_entry(patch, &klp_patches, list) {
+       klp_for_each_patch(patch) {
                klp_for_each_object(patch, obj) {
                        if (!klp_is_module(obj) || strcmp(obj->name, mod->name))
                                continue;
index e6200f38701fc412241af88112ded85f54ba984c..ec43a40b853fc6c478b0280c030ca37944becdf2 100644 (file)
@@ -7,6 +7,12 @@
 extern struct mutex klp_mutex;
 extern struct list_head klp_patches;
 
+#define klp_for_each_patch_safe(patch, tmp_patch)              \
+       list_for_each_entry_safe(patch, tmp_patch, &klp_patches, list)
+
+#define klp_for_each_patch(patch)      \
+       list_for_each_entry(patch, &klp_patches, list)
+
 void klp_free_patch_start(struct klp_patch *patch);
 void klp_discard_replaced_patches(struct klp_patch *new_patch);
 void klp_discard_nops(struct klp_patch *new_patch);
index 3002738196740807ebe630c1e9c67b497c106cfe..a3a6f32c6fd094886a67745f89e3ac1480760d7a 100644 (file)
@@ -642,6 +642,6 @@ void klp_force_transition(void)
        for_each_possible_cpu(cpu)
                klp_update_patch_state(idle_task(cpu));
 
-       list_for_each_entry(patch, &klp_patches, list)
+       klp_for_each_patch(patch)
                patch->forced = true;
 }