Skip to content

Commit

Permalink
livepatch: Introduce klp_for_each_patch macro
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Miroslav Benes <[email protected]>
Acked-by: Joe Lawrence <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
  • Loading branch information
pmladek committed Feb 6, 2019
1 parent 375bfca commit ecba29f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions kernel/livepatch/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions kernel/livepatch/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion kernel/livepatch/transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit ecba29f

Please sign in to comment.