Skip to contentSkip to conversation

livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication

PATCH Applied Zhen Lei 4 participants 7 messages Dec 7, 2022 – Dec 10, 2022 Live patching

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

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
index 50bfc3481a4ee38..201f0c0482fb56d 100644
@@ -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
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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.

#2 lore raw
Quoted 10 lines · Song Liu
Quoted 7 lines · 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.

Thanks, applied to modules-next given this depends on the kallsyms stuff there. Pushed out.

Luis

#4 lore raw
Quoted 11 lines · Petr Mladek
Quoted 6 lines · 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.

Thanks for cleaning this.

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
maintainer
#5 lore raw
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 function klp_find_callback(). So call function klp_match_callback() in function klp_find_callback() instead of the duplicated code.

Thanks for cleaning this.

Quoted 7 lines
Quoted 1 line

Oh, sorry, I realized that I had forgotten to add:

Hi Luis:
Can you help me add it?

JFYI, I could live without it ;-)

Best Regards,
Petr

#6 lore raw
In reply to Leizhen (ThunderTown)
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 function klp_find_callback(). So call function klp_match_callback() in function klp_find_callback() instead of the duplicated code.

Thanks for cleaning this.

Quoted 7 lines
Quoted 1 line

Oh, sorry, I realized that I had forgotten to add:

Hi Luis:
Can you help me add it?

Done!

Luis