Re: [PATCH v13 08/12] livepatch: Add atomic replace

From: Miroslav Benes
Date: Fri Nov 23 2018 - 07:00:40 EST


On Mon, 15 Oct 2018, Petr Mladek wrote:

> +static int klp_add_object_nops(struct klp_patch *patch,
> + struct klp_object *old_obj)
> +{
> + struct klp_object *obj;
> + struct klp_func *func, *old_func;
> +
> + obj = klp_find_object(patch, old_obj);
> +
> + if (!obj) {
> + obj = klp_alloc_object_dynamic(old_obj->name);
> + if (!obj)
> + return -ENOMEM;
> +
> + list_add(&obj->node, &patch->obj_list);
> + }
> +
> + klp_for_each_func(old_obj, old_func) {
> + func = klp_find_func(obj, old_func);
> + if (func)
> + continue;
> +
> + func = klp_alloc_func_nop(old_func, obj);
> + if (!func)
> + return -ENOMEM;
> +
> + list_add(&func->node, &obj->func_list);
> + }
> +
> + return 0;
> +}

Maybe you should consider list_add_tail() here too.

> +
> +/*
> + * Add 'nop' functions which simply return to the caller to run
> + * the original function. The 'nop' functions are added to a
> + * patch to facilitate a 'replace' mode.
> + */
> +static int klp_add_nops(struct klp_patch *patch)
> +{
> + struct klp_patch *old_patch;
> + struct klp_object *old_obj;
> + int err = 0;

The initialization is unnecessary.

> + list_for_each_entry(old_patch, &klp_patches, list) {
> + klp_for_each_object(old_patch, old_obj) {
> + err = klp_add_object_nops(patch, old_obj);
> + if (err)
> + return err;
> + }
> + }
> +
> + return 0;
> +}

Miroslav