[PATCH 03/13] livepatch: refactor klp_init_object

From: Christoph Hellwig
Date: Thu Jan 21 2021 - 02:59:14 EST


Merge three calls to klp_is_module (including one hidden inside
klp_find_object_module) into a single one to simplify the code a bit.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
kernel/livepatch/core.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index f76fdb9255323d..a7f625dc24add3 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -54,9 +54,6 @@ static void klp_find_object_module(struct klp_object *obj)
{
struct module *mod;

- if (!klp_is_module(obj))
- return;
-
mutex_lock(&module_mutex);
/*
* We do not want to block removal of patched modules and therefore
@@ -73,7 +70,6 @@ static void klp_find_object_module(struct klp_object *obj)
*/
if (mod && mod->klp_alive)
obj->mod = mod;
-
mutex_unlock(&module_mutex);
}

@@ -823,15 +819,19 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
int ret;
const char *name;

- if (klp_is_module(obj) && strlen(obj->name) >= MODULE_NAME_LEN)
- return -EINVAL;
-
obj->patched = false;
obj->mod = NULL;

- klp_find_object_module(obj);
+ if (klp_is_module(obj)) {
+ if (strlen(obj->name) >= MODULE_NAME_LEN)
+ return -EINVAL;
+ name = obj->name;
+
+ klp_find_object_module(obj);
+ } else {
+ name = "vmlinux";
+ }

- name = klp_is_module(obj) ? obj->name : "vmlinux";
ret = kobject_add(&obj->kobj, &patch->kobj, "%s", name);
if (ret)
return ret;
--
2.29.2