Thread (47 messages) 47 messages, 5 authors, 8h ago

Re: [PATCH v3 2/7] livepatch: Move klp_find_func() into core.h

From: Yafang Shao <hidden>
Date: 2026-06-10 03:01:48

On Tue, Jun 9, 2026 at 11:28 PM Petr Mladek [off-list ref] wrote:
On Sun 2026-06-07 21:16:54, Yafang Shao wrote:
quoted
This function will be used in other source file in the following patch.

Signed-off-by: Yafang Shao <redacted>
---
 kernel/livepatch/core.c | 21 ---------------------
 kernel/livepatch/core.h | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 95117f7a5b00..6e15ae96a0a7 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -82,27 +82,6 @@ static bool klp_initialized(void)
      return !!klp_root_kobj;
 }

-static struct klp_func *klp_find_func(struct klp_object *obj,
-                                   struct klp_func *old_func)
-{
-     struct klp_func *func;
-
-     klp_for_each_func(obj, func) {
-             /*
-              * Besides identical old_sympos, also consider old_sympos
-              * of 0 and 1 are identical.
-              */
-             if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&
-                 ((old_func->old_sympos == func->old_sympos) ||
-                  (old_func->old_sympos == 0 && func->old_sympos == 1) ||
-                  (old_func->old_sympos == 1 && func->old_sympos == 0))) {
-                     return func;
-             }
-     }
-
-     return NULL;
-}
-
 static struct klp_object *klp_find_object(struct klp_patch *patch,
                                        struct klp_object *old_obj)
 {
diff --git a/kernel/livepatch/core.h b/kernel/livepatch/core.h
index 38209c7361b6..8f01eae875eb 100644
--- a/kernel/livepatch/core.h
+++ b/kernel/livepatch/core.h
@@ -56,4 +56,25 @@ static inline void klp_post_unpatch_callback(struct klp_object *obj)
      obj->callbacks.post_unpatch_enabled = false;
 }

+static inline struct klp_func *klp_find_func(struct klp_object *obj,
+                                          struct klp_func *old_func)
+{
+     struct klp_func *func;
+
+     klp_for_each_func(obj, func) {
+             /*
+              * Besides identical old_sympos, also consider old_sympos
+              * of 0 and 1 are identical.
+              */
+             if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&
+                 ((old_func->old_sympos == func->old_sympos) ||
+                  (old_func->old_sympos == 0 && func->old_sympos == 1) ||
+                  (old_func->old_sympos == 1 && func->old_sympos == 0))) {
+                     return func;
+             }
+     }
+
+     return NULL;
+}
This is too big for in-lining to my taste. I would prefer to just
remove the static and declare it in the header file.

Also it would be nice to add a description of the function when we are
going to use it on more locations. Especially, if we allow to pass
errors via ERR_PTR.
I will update it.

-- 
Regards
Yafang
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help