livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
PATCH 1/1 livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
The implementation of function klp_match_callback() is identical to the partial implementation of function klp_find_callback(). So call function klp_match_callback() in function klp_find_callback() instead of the duplicated code.
--- kernel/livepatch/core.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)
kernel/livepatch/core.c +11 -22
@@ -125,20 +125,10 @@ struct klp_find_arg {unsigned long pos; }; -static int klp_find_callback (void *data,const char *name, -struct module *mod,unsigned long addr) +static int klp_match_callback (void *data,unsigned long addr) {struct klp_find_arg *args = data; -if ((mod && !args->objname) || (!mod && args->objname)) -return 0 ; - -if (strcmp (args->name, name)) -return 0 ; - -if (args->objname &&strcmp (args->objname, mod->name)) -return 0 ; - args->addr = addr; args->count++;
@@ -153,22 +143,21 @@ static int klp_find_callback(void *data, const char *name,return 0 ; } -static int klp_match_callback (void *data,unsigned long addr) +static int klp_find_callback (void *data,const char *name, +struct module *mod,unsigned long addr) {struct klp_find_arg *args = data; - args->addr = addr; - args->count++; +if ((mod && !args->objname) || (!mod && args->objname)) +return 0 ; -/* -* Finish the search when the symbol is found for the desired position -* or the position is not defined for a non-unique symbol. -*/ -if ((args->pos && (args->count == args->pos)) || - (!args->pos && (args->count >1 ))) -return 1 ; +if (strcmp (args->name, name)) +return 0 ; -return 0 ; +if (args->objname &&strcmp (args->objname, mod->name)) +return 0 ; + +return klp_match_callback (data, addr); } static int klp_find_object_symbol(const char *objname, const char *name,
Signature · 1 line
2.25.1
Quoted 7 lines · Zhen Lei
The implementation of function
klp_match_callback()is identical to the partial implementation of functionklp_find_callback(). So call functionklp_match_callback()in functionklp_find_callback()instead of the duplicated code.Signed-off-by Zhen Lei <[email protected]>
Luis Chamberlain
AppliedQuoted 10 lines · Song Liu
Quoted 7 lines · Zhen Lei
The implementation of function
klp_match_callback()is identical to the partial implementation of functionklp_find_callback(). So call functionklp_match_callback()in functionklp_find_callback()instead of the duplicated code.Signed-off-by Zhen Lei <[email protected]>Acked-by Song Liu <[email protected]>
Thanks, applied to modules-next given this depends on the kallsyms stuff there. Pushed out.
Luis
Quoted 6 lines · Zhen Lei
The implementation of function
klp_match_callback()is identical to the partial implementation of functionklp_find_callback(). So call functionklp_match_callback()in functionklp_find_callback()instead of the duplicated code.Signed-off-by Zhen Lei <[email protected]>
Thanks for cleaning this.
Best Regards,
Petr
Quoted 11 lines · Petr Mladek
Quoted 6 lines · Zhen Lei
The implementation of function
klp_match_callback()is identical to the partial implementation of functionklp_find_callback(). So call functionklp_match_callback()in functionklp_find_callback()instead of the duplicated code.Signed-off-by Zhen Lei <[email protected]>Thanks for cleaning this.
Reviewed-by Petr Mladek <[email protected]>
Oh, sorry, I realized that I had forgotten to add:
Hi Luis:
Can you help me add it?
Quoted 5 lines
Best Regards,
Petr
.
Signature · 2 lines
Regards, Zhen Lei
Petr Mladek
maintainerQuoted 13 lines · Leizhen (ThunderTown)
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Zhen Lei
The implementation of function
klp_match_callback()is identical to the partial implementation of functionklp_find_callback(). So call functionklp_match_callback()in functionklp_find_callback()instead of the duplicated code.Signed-off-by Zhen Lei <[email protected]>Thanks for cleaning this.
Quoted 7 lines
Quoted 1 line
Reviewed-by Petr Mladek <[email protected]>Oh, sorry, I realized that I had forgotten to add:
Suggested-by Petr Mladek <[email protected]>Hi Luis:
Can you help me add it?
JFYI, I could live without it ;-)
Best Regards,
Petr
Quoted 13 lines · Leizhen (ThunderTown)
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Zhen Lei
The implementation of function
klp_match_callback()is identical to the partial implementation of functionklp_find_callback(). So call functionklp_match_callback()in functionklp_find_callback()instead of the duplicated code.Signed-off-by Zhen Lei <[email protected]>Thanks for cleaning this.
Quoted 7 lines
Quoted 1 line
Reviewed-by Petr Mladek <[email protected]>Oh, sorry, I realized that I had forgotten to add:
Suggested-by Petr Mladek <[email protected]>Hi Luis:
Can you help me add it?
Done!
Luis