Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Stange <nstange@suse.de>2017-10-31 10:34:53 +0100
committerMiroslav Benes <mbenes@suse.cz>2017-12-08 15:30:44 +0100
commit6552b44c7c3c98b32fdaeb0212121c61eab3c136 (patch)
treea436a74dcbaaa2634b1c64d74003f865a415c819
parent0fe721be0894cac6d25b13ef0f575a554345e321 (diff)
livepatch_main.c: klp_patch_init(): fix error handling
In case either of the invocations of klp_register_patch() or klp_enable_patch() fails, anything which has been setup by the prior per-(sub-)patch initialiation code, i.e. the expansion of @@KLP_PATCHES_INIT_CALLS@@, won't get undone. Fix this. Also make klp_patch_init() look more like the common 'goto err' idiom and adjust scripts/register_patches.sh accordingly. Fix for commit 7e20201cdcb8 ("kGraft to livepatch migration. API change."). Signed-off-by: Nicolai Stange <nstange@suse.de> Signed-off-by: Miroslav Benes <mbenes@suse.cz>
-rw-r--r--livepatch_main.c12
-rwxr-xr-xscripts/register-patches.sh3
2 files changed, 7 insertions, 8 deletions
diff --git a/livepatch_main.c b/livepatch_main.c
index c002ac5..c0dc36b 100644
--- a/livepatch_main.c
+++ b/livepatch_main.c
@@ -49,15 +49,15 @@ static int __init klp_patch_init(void)
retval = klp_register_patch(&patch);
if (retval)
- return retval;
+ goto err_patches_cleanup;
retval = klp_enable_patch(&patch);
- if (retval) {
- WARN_ON(klp_unregister_patch(&patch));
+ if (!retval)
return retval;
- }
- /* jumped to from expanded KLP_PATCHES_INIT_CALLS on failure */
-@@KLP_PATCHES_INIT_ERR_HANDLERS@@:
+ WARN_ON(klp_unregister_patch(&patch));
+
+err_patches_cleanup:
+ @@KLP_PATCHES_INIT_ERR_HANDLERS@@;
return retval;
}
diff --git a/scripts/register-patches.sh b/scripts/register-patches.sh
index 47aba14..93a4121 100755
--- a/scripts/register-patches.sh
+++ b/scripts/register-patches.sh
@@ -158,7 +158,6 @@ KLP_PATCHES_INIT_ERR_HANDLERS=$(
err_${livepatches[$i]}:
EOF
done | sed 's%\t%\\t%g' | sed 's%$%\\n%g' | tr -d '\n';
- echo "\treturn retval;"
)
## Cleanup the individual patches in livepatch_cleanup().
@@ -172,7 +171,7 @@ sed -i -f - "$livepatch_main_file" <<EOF
s%@@KLP_PATCHES_INCLUDES@@%$KLP_PATCHES_INCLUDES%;
s%\s*@@KLP_PATCHES_OBJS@@,\?%$KLP_PATCHES_OBJS%;
s%\s*@@KLP_PATCHES_INIT_CALLS@@;\?%$KLP_PATCHES_INIT_CALLS%;
-s%\s*@@KLP_PATCHES_INIT_ERR_HANDLERS@@:\?%$KLP_PATCHES_INIT_ERR_HANDLERS%;
+s%\s*@@KLP_PATCHES_INIT_ERR_HANDLERS@@;\?%$KLP_PATCHES_INIT_ERR_HANDLERS%;
s%\s*@@KLP_PATCHES_CLEANUP_CALLS@@;\?%$KLP_PATCHES_CLEANUP_CALLS%;
s%\s*@@KLP_PATCHES_CLEANUP_CALLS@@;\?%$KLP_PATCHES_CLEANUP_CALLS%;
EOF