Re: [PATCH v2 59/62] livepatch/klp-build: Introduce klp-build script for generating livepatch modules
From: Josh Poimboeuf
Date: Fri Jun 06 2025 - 17:35:38 EST
On Fri, Jun 06, 2025 at 04:58:35PM -0400, Joe Lawrence wrote:
> On 5/9/25 4:17 PM, Josh Poimboeuf wrote:
> > +copy_patched_objects() {
> > + local found
> > + local files=()
> > + local opts=()
> > +
> > + rm -rf "$PATCHED_DIR"
> > + mkdir -p "$PATCHED_DIR"
> > +
> > + # Note this doesn't work with some configs, thus the 'cmp' below.
> > + opts=("-newer")
> > + opts+=("$TIMESTAMP")
> > +
> > + find_objects "${opts[@]}" | mapfile -t files
> > +
> > + xtrace_save "processing all objects"
> > + for _file in "${files[@]}"; do
> > + local rel_file="${_file/.ko/.o}"
> > + local file="$OBJ/$rel_file"
> > + local orig_file="$ORIG_DIR/$rel_file"
> > + local patched_file="$PATCHED_DIR/$rel_file"
> > +
> > + [[ ! -f "$file" ]] && die "missing $(basename "$file") for $_file"
> > +
> > + cmp -s "$orig_file" "$file" && continue
> > +
> > + mkdir -p "$(dirname "$patched_file")"
> > + cp -f "$file" "$patched_file"
> > + found=1
> > + done
> > + xtrace_restore
> > +
> > + [[ -n "$found" ]] || die "no changes detected"
> > +
>
> Minor nit here, I gave it a patch for files that didn't compile and
> because because files() was presumably empty:
>
> ./scripts/livepatch/klp-build: line 564: found: unbound variable
>
> since found was only declared local, but never set inside the loop.
Thanks, I'm adding the following:
diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index 9927d06dfdab..f689a4d143c6 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -563,7 +563,7 @@ copy_orig_objects() {
copy_patched_objects() {
local files=()
local opts=()
- local found
+ local found=0
rm -rf "$PATCHED_DIR"
mkdir -p "$PATCHED_DIR"
@@ -592,7 +592,7 @@ copy_patched_objects() {
done
xtrace_restore
- [[ -n "$found" ]] || die "no changes detected"
+ (( found == 0 )) && die "no changes detected"
mv -f "$TMP_DIR/build.log" "$PATCHED_DIR"
}