[PATCH v2 02/12] klp-build: Process the patches before building the original kernel

From
Song Liu <song@kernel.org>
Date
2026-10-28 21:45:50
Also in
linux-kselftest, lkml
Reply to
Song Liu, 2026-10-28
klp-build validates the patches before building the original kernel,
but only combines them and adds #line directives after the build, which
applies and reverts them a second time.  Nothing in the second step
needs the original build, but the errors it finds, like patches with no
net effect, only show up after a full kernel build.

Do both in one step, before the build.  process_patches() checks for
patches to unsupported files, then applies the patches in order, which
also catches patches that don't apply and warns about those which apply
with fuzz, and combines them.

Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@kernel.org>
---
 scripts/livepatch/klp-build | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index a0bfc40093f9..28c3bf6b6418 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -395,11 +395,10 @@ revert_patch() {
 }
 
 apply_patches() {
-	local extra_args=("$@")
 	local patch
 
 	for patch in "${PATCHES[@]}"; do
-		apply_patch "$patch" "${extra_args[@]}"
+		apply_patch "$patch"
 	done
 }
 
@@ -413,12 +412,6 @@ revert_patches() {
 	APPLIED_PATCHES=()
 }
 
-validate_patches() {
-	check_unsupported_patches
-	apply_patches
-	revert_patches
-}
-
 do_init() {
 	# We're not yet smart enough to handle anything other than in-tree
 	# builds in pwd.
@@ -478,7 +471,7 @@ combine_patches() {
 	# Diff the orig source files against the patched ones in place to make a
 	# clean patch.  Use /dev/null for created and deleted files.
 	: > "$outfile"
-	apply_patches "--silent"
+	apply_patches
 	for file in "${files[@]}"; do
 		local old="$tmpdir/$file"
 		local new="$file"
@@ -504,12 +497,13 @@ combine_patches() {
 	revert_patches
 }
 
-# Combine the patches into $COMBINED_PATCH, and fix its lines so as not to
-# affect the __LINE__ macro for otherwise unchanged functions further down the
-# file.
+# Validate the patches, combine them into $COMBINED_PATCH, and fix its lines so
+# as not to affect the __LINE__ macro for otherwise unchanged functions further
+# down the file.
 process_patches() {
 	local tmp_patch="$TMP_DIR/tmp.patch"
 
+	check_unsupported_patches
 	combine_patches "$tmp_patch"
 	[[ ! -s "$tmp_patch" ]] && die "no changes detected"
 
@@ -889,8 +883,8 @@ process_args "$@"
 do_init
 
 if (( SHORT_CIRCUIT <= 2 )); then
-	status "Validating patch(es)"
-	validate_patches
+	status "Processing patch(es)"
+	process_patches
 fi
 
 if (( SHORT_CIRCUIT <= 1 )); then
@@ -902,8 +896,6 @@ if (( SHORT_CIRCUIT <= 1 )); then
 fi
 
 if (( SHORT_CIRCUIT <= 2 )); then
-	status "Processing patch(es)"
-	process_patches
 	apply_patch "$COMBINED_PATCH" "--silent"
 	status "Building patched kernel"
 	build_kernel "patched"
-- 
2.53.0-Meta
Thread (18 messages) 18 messages, 4 authors, last reply 4d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help