From 6a69f5f91a89a691288b844ed79b19b786d5c3a7 Mon Sep 17 00:00:00 2001 From: Jessica Yu Date: Thu, 14 Aug 2014 09:23:33 -0700 Subject: [PATCH] consolidate variables func->old_offset and func->old_addr to just old_addr To reduce redundancy, remove/change the old_offset fields in the kpatch_func and kpatch_patch_func structs to just old_addr. Since old_offset is being used as a placeholder for old_addr, might as well consolidate it to just one variable. --- kmod/core/core.c | 9 ++++----- kmod/core/kpatch.h | 3 +-- kmod/patch/kpatch-patch-hook.c | 3 +-- kmod/patch/kpatch-patch.h | 2 +- kpatch-build/create-diff-object.c | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/kmod/core/core.c b/kmod/core/core.c index 8c1bb37..e17234b 100644 --- a/kmod/core/core.c +++ b/kmod/core/core.c @@ -711,16 +711,15 @@ static int kpatch_link_object(struct kpatch_module *kpmod, goto err_unlink; list_for_each_entry(func, &object->funcs, list) { - unsigned long old_addr; /* calculate actual old location */ if (vmlinux) { - old_addr = func->old_offset; ret = kpatch_verify_symbol_match(func->name, - old_addr); + func->old_addr); if (ret) goto err_unlink; } else { + unsigned long old_addr; old_addr = kpatch_find_module_symbol(mod, func->name); if (!old_addr) { pr_err("unable to find symbol '%s' in module '%s\n", @@ -728,14 +727,14 @@ static int kpatch_link_object(struct kpatch_module *kpmod, ret = -EINVAL; goto err_unlink; } + func->old_addr = old_addr; } /* add to ftrace filter and register handler if needed */ - ret = kpatch_ftrace_add_func(old_addr); + ret = kpatch_ftrace_add_func(func->old_addr); if (ret) goto err_unlink; - func->old_addr = old_addr; } return 0; diff --git a/kmod/core/kpatch.h b/kmod/core/kpatch.h index be73593..7523227 100644 --- a/kmod/core/kpatch.h +++ b/kmod/core/kpatch.h @@ -36,7 +36,7 @@ struct kpatch_func { /* public */ unsigned long new_addr; unsigned long new_size; - unsigned long old_offset; + unsigned long old_addr; unsigned long old_size; const char *name; struct list_head list; @@ -44,7 +44,6 @@ struct kpatch_func { /* private */ struct hlist_node node; - unsigned long old_addr; enum kpatch_op op; }; diff --git a/kmod/patch/kpatch-patch-hook.c b/kmod/patch/kpatch-patch-hook.c index b957a61..b901c54 100644 --- a/kmod/patch/kpatch-patch-hook.c +++ b/kmod/patch/kpatch-patch-hook.c @@ -257,9 +257,8 @@ static int patch_make_funcs_list(struct list_head *objects) func->new_addr = p_func->new_addr; func->new_size = p_func->new_size; - /* find correct func->old_offset */ if (!strcmp("vmlinux", object->name)) - func->old_offset = p_func->old_offset; + func->old_addr = p_func->old_addr; else func->old_addr = 0x0; diff --git a/kmod/patch/kpatch-patch.h b/kmod/patch/kpatch-patch.h index 7f013e9..3ce4832 100644 --- a/kmod/patch/kpatch-patch.h +++ b/kmod/patch/kpatch-patch.h @@ -25,7 +25,7 @@ struct kpatch_patch_func { unsigned long new_addr; unsigned long new_size; - unsigned long old_offset; + unsigned long old_addr; unsigned long old_size; char *name; char *objname; diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 52d9e57..849a92e 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -1983,7 +1983,7 @@ void kpatch_create_patches_sections(struct kpatch_elf *kelf, sym->name, result.value, result.size); /* add entry in text section */ - funcs[index].old_offset = result.value; + funcs[index].old_addr = result.value; funcs[index].old_size = result.size; funcs[index].new_size = sym->sym.st_size;