提交 8cdd043a 编写于 作者: J Jiri Slaby 提交者: Jiri Kosina

livepatch: introduce patch/func-walking helpers

klp_for_each_object and klp_for_each_func are now used all over the
code. One need not think what is the proper condition to check in the
for loop now.
Signed-off-by: NJiri Slaby <jslaby@suse.cz>
Acked-by: NJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 cad706df
...@@ -123,6 +123,12 @@ struct klp_patch { ...@@ -123,6 +123,12 @@ struct klp_patch {
enum klp_state state; enum klp_state state;
}; };
#define klp_for_each_object(patch, obj) \
for (obj = patch->objs; obj->funcs; obj++)
#define klp_for_each_func(obj, func) \
for (func = obj->funcs; func->old_name; func++)
int klp_register_patch(struct klp_patch *); int klp_register_patch(struct klp_patch *);
int klp_unregister_patch(struct klp_patch *); int klp_unregister_patch(struct klp_patch *);
int klp_enable_patch(struct klp_patch *); int klp_enable_patch(struct klp_patch *);
......
...@@ -422,7 +422,7 @@ static void klp_disable_object(struct klp_object *obj) ...@@ -422,7 +422,7 @@ static void klp_disable_object(struct klp_object *obj)
{ {
struct klp_func *func; struct klp_func *func;
for (func = obj->funcs; func->old_name; func++) klp_for_each_func(obj, func)
if (func->state == KLP_ENABLED) if (func->state == KLP_ENABLED)
klp_disable_func(func); klp_disable_func(func);
...@@ -440,7 +440,7 @@ static int klp_enable_object(struct klp_object *obj) ...@@ -440,7 +440,7 @@ static int klp_enable_object(struct klp_object *obj)
if (WARN_ON(!klp_is_object_loaded(obj))) if (WARN_ON(!klp_is_object_loaded(obj)))
return -EINVAL; return -EINVAL;
for (func = obj->funcs; func->old_name; func++) { klp_for_each_func(obj, func) {
ret = klp_enable_func(func); ret = klp_enable_func(func);
if (ret) { if (ret) {
klp_disable_object(obj); klp_disable_object(obj);
...@@ -463,7 +463,7 @@ static int __klp_disable_patch(struct klp_patch *patch) ...@@ -463,7 +463,7 @@ static int __klp_disable_patch(struct klp_patch *patch)
pr_notice("disabling patch '%s'\n", patch->mod->name); pr_notice("disabling patch '%s'\n", patch->mod->name);
for (obj = patch->objs; obj->funcs; obj++) { klp_for_each_object(patch, obj) {
if (obj->state == KLP_ENABLED) if (obj->state == KLP_ENABLED)
klp_disable_object(obj); klp_disable_object(obj);
} }
...@@ -523,7 +523,7 @@ static int __klp_enable_patch(struct klp_patch *patch) ...@@ -523,7 +523,7 @@ static int __klp_enable_patch(struct klp_patch *patch)
pr_notice("enabling patch '%s'\n", patch->mod->name); pr_notice("enabling patch '%s'\n", patch->mod->name);
for (obj = patch->objs; obj->funcs; obj++) { klp_for_each_object(patch, obj) {
if (!klp_is_object_loaded(obj)) if (!klp_is_object_loaded(obj))
continue; continue;
...@@ -689,7 +689,7 @@ static void klp_free_object_loaded(struct klp_object *obj) ...@@ -689,7 +689,7 @@ static void klp_free_object_loaded(struct klp_object *obj)
obj->mod = NULL; obj->mod = NULL;
for (func = obj->funcs; func->old_name; func++) klp_for_each_func(obj, func)
func->old_addr = 0; func->old_addr = 0;
} }
...@@ -738,7 +738,7 @@ static int klp_init_object_loaded(struct klp_patch *patch, ...@@ -738,7 +738,7 @@ static int klp_init_object_loaded(struct klp_patch *patch,
return ret; return ret;
} }
for (func = obj->funcs; func->old_name; func++) { klp_for_each_func(obj, func) {
ret = klp_find_verify_func_addr(obj, func); ret = klp_find_verify_func_addr(obj, func);
if (ret) if (ret)
return ret; return ret;
...@@ -767,7 +767,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj) ...@@ -767,7 +767,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
if (ret) if (ret)
return ret; return ret;
for (func = obj->funcs; func->old_name; func++) { klp_for_each_func(obj, func) {
ret = klp_init_func(obj, func); ret = klp_init_func(obj, func);
if (ret) if (ret)
goto free; goto free;
...@@ -804,7 +804,7 @@ static int klp_init_patch(struct klp_patch *patch) ...@@ -804,7 +804,7 @@ static int klp_init_patch(struct klp_patch *patch)
if (ret) if (ret)
goto unlock; goto unlock;
for (obj = patch->objs; obj->funcs; obj++) { klp_for_each_object(patch, obj) {
ret = klp_init_object(patch, obj); ret = klp_init_object(patch, obj);
if (ret) if (ret)
goto free; goto free;
...@@ -961,7 +961,7 @@ static int klp_module_notify(struct notifier_block *nb, unsigned long action, ...@@ -961,7 +961,7 @@ static int klp_module_notify(struct notifier_block *nb, unsigned long action,
mod->klp_alive = false; mod->klp_alive = false;
list_for_each_entry(patch, &klp_patches, list) { list_for_each_entry(patch, &klp_patches, list) {
for (obj = patch->objs; obj->funcs; obj++) { klp_for_each_object(patch, obj) {
if (!klp_is_module(obj) || strcmp(obj->name, mod->name)) if (!klp_is_module(obj) || strcmp(obj->name, mod->name))
continue; continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册