* [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
@ 2022-12-07 3:23 Zhen Lei
2022-12-09 0:11 ` Song Liu
2022-12-09 9:12 ` Petr Mladek
0 siblings, 2 replies; 7+ messages in thread
From: Zhen Lei @ 2022-12-07 3:23 UTC (permalink / raw)
To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
Joe Lawrence, live-patching, linux-kernel, Masahiro Yamada,
Alexei Starovoitov, Jiri Olsa, Kees Cook, Andrew Morton,
Luis Chamberlain, linux-modules
Cc: Zhen Lei
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.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
kernel/livepatch/core.c | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 50bfc3481a4ee38..201f0c0482fb56d 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -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,
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
2022-12-07 3:23 [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication Zhen Lei
@ 2022-12-09 0:11 ` Song Liu
2022-12-09 0:22 ` Luis Chamberlain
2022-12-09 9:12 ` Petr Mladek
1 sibling, 1 reply; 7+ messages in thread
From: Song Liu @ 2022-12-09 0:11 UTC (permalink / raw)
To: Zhen Lei
Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
Joe Lawrence, live-patching, linux-kernel, Masahiro Yamada,
Alexei Starovoitov, Jiri Olsa, Kees Cook, Andrew Morton,
Luis Chamberlain, linux-modules
On Tue, Dec 6, 2022 at 7:25 PM Zhen Lei <thunder.leizhen@huawei.com> wrote:
>
> 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.
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Acked-by: Song Liu <song@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
2022-12-09 0:11 ` Song Liu
@ 2022-12-09 0:22 ` Luis Chamberlain
0 siblings, 0 replies; 7+ messages in thread
From: Luis Chamberlain @ 2022-12-09 0:22 UTC (permalink / raw)
To: Song Liu
Cc: Zhen Lei, Josh Poimboeuf, Jiri Kosina, Miroslav Benes,
Petr Mladek, Joe Lawrence, live-patching, linux-kernel,
Masahiro Yamada, Alexei Starovoitov, Jiri Olsa, Kees Cook,
Andrew Morton, linux-modules
On Thu, Dec 08, 2022 at 04:11:06PM -0800, Song Liu wrote:
> On Tue, Dec 6, 2022 at 7:25 PM Zhen Lei <thunder.leizhen@huawei.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>
> Acked-by: Song Liu <song@kernel.org>
Thanks, applied to modules-next given this depends on the kallsyms stuff there.
Pushed out.
Luis
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
2022-12-07 3:23 [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication Zhen Lei
2022-12-09 0:11 ` Song Liu
@ 2022-12-09 9:12 ` Petr Mladek
2022-12-09 11:29 ` Leizhen (ThunderTown)
1 sibling, 1 reply; 7+ messages in thread
From: Petr Mladek @ 2022-12-09 9:12 UTC (permalink / raw)
To: Zhen Lei
Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Joe Lawrence,
live-patching, linux-kernel, Masahiro Yamada, Alexei Starovoitov,
Jiri Olsa, Kees Cook, Andrew Morton, Luis Chamberlain,
linux-modules
On Wed 2022-12-07 11:23:04, Zhen Lei wrote:
> 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.
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Thanks for cleaning this.
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
2022-12-09 9:12 ` Petr Mladek
@ 2022-12-09 11:29 ` Leizhen (ThunderTown)
2022-12-09 14:36 ` Petr Mladek
2022-12-10 1:09 ` Luis Chamberlain
0 siblings, 2 replies; 7+ messages in thread
From: Leizhen (ThunderTown) @ 2022-12-09 11:29 UTC (permalink / raw)
To: Petr Mladek
Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Joe Lawrence,
live-patching, linux-kernel, Masahiro Yamada, Alexei Starovoitov,
Jiri Olsa, Kees Cook, Andrew Morton, Luis Chamberlain,
linux-modules
On 2022/12/9 17:12, Petr Mladek wrote:
> On Wed 2022-12-07 11:23:04, Zhen Lei wrote:
>> 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.
>>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>
> Thanks for cleaning this.
>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
Oh, sorry, I realized that I had forgotten to add:
Suggested-by: Petr Mladek <pmladek@suse.com>
Hi Luis:
Can you help me add it?
>
> Best Regards,
> Petr
> .
>
--
Regards,
Zhen Lei
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
2022-12-09 11:29 ` Leizhen (ThunderTown)
@ 2022-12-09 14:36 ` Petr Mladek
2022-12-10 1:09 ` Luis Chamberlain
1 sibling, 0 replies; 7+ messages in thread
From: Petr Mladek @ 2022-12-09 14:36 UTC (permalink / raw)
To: Leizhen (ThunderTown)
Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Joe Lawrence,
live-patching, linux-kernel, Masahiro Yamada, Alexei Starovoitov,
Jiri Olsa, Kees Cook, Andrew Morton, Luis Chamberlain,
linux-modules
On Fri 2022-12-09 19:29:56, Leizhen (ThunderTown) wrote:
>
>
> On 2022/12/9 17:12, Petr Mladek wrote:
> > On Wed 2022-12-07 11:23:04, Zhen Lei wrote:
> >> 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.
> >>
> >> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> >
> > Thanks for cleaning this.
> >
> > Reviewed-by: Petr Mladek <pmladek@suse.com>
>
> Oh, sorry, I realized that I had forgotten to add:
> Suggested-by: Petr Mladek <pmladek@suse.com>
>
> Hi Luis:
> Can you help me add it?
JFYI, I could live without it ;-)
Best Regards,
Petr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication
2022-12-09 11:29 ` Leizhen (ThunderTown)
2022-12-09 14:36 ` Petr Mladek
@ 2022-12-10 1:09 ` Luis Chamberlain
1 sibling, 0 replies; 7+ messages in thread
From: Luis Chamberlain @ 2022-12-10 1:09 UTC (permalink / raw)
To: Leizhen (ThunderTown)
Cc: Petr Mladek, Josh Poimboeuf, Jiri Kosina, Miroslav Benes,
Joe Lawrence, live-patching, linux-kernel, Masahiro Yamada,
Alexei Starovoitov, Jiri Olsa, Kees Cook, Andrew Morton,
linux-modules
On Fri, Dec 09, 2022 at 07:29:56PM +0800, Leizhen (ThunderTown) wrote:
>
>
> On 2022/12/9 17:12, Petr Mladek wrote:
> > On Wed 2022-12-07 11:23:04, Zhen Lei wrote:
> >> 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.
> >>
> >> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> >
> > Thanks for cleaning this.
> >
> > Reviewed-by: Petr Mladek <pmladek@suse.com>
>
> Oh, sorry, I realized that I had forgotten to add:
> Suggested-by: Petr Mladek <pmladek@suse.com>
>
> Hi Luis:
> Can you help me add it?
Done!
Luis
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-12-10 1:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-07 3:23 [PATCH] livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication Zhen Lei
2022-12-09 0:11 ` Song Liu
2022-12-09 0:22 ` Luis Chamberlain
2022-12-09 9:12 ` Petr Mladek
2022-12-09 11:29 ` Leizhen (ThunderTown)
2022-12-09 14:36 ` Petr Mladek
2022-12-10 1:09 ` Luis Chamberlain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox