On Wed, Feb 04, 2026 at 10:02:38AM -0800, Josh Poimboeuf wrote:
> On Tue, Feb 03, 2026 at 09:51:37PM -0500, Joe Lawrence wrote:
> > The klp-build script prepares a clean patch by populating two temporary
> > directories ('a' and 'b') with source files and diffing the result.
> > However, this process currently fails when a patch introduces a new
> > source file as the script attempts to copy files that do not yet exist
> > in the original source tree. Likewise, there is a similar limitation
> > when a patch removes a source file and the script tries to copy files
> > that no longer exist.
> >
> > Refactor the file-gathering logic to distinguish between original input
> > files and patched output files:
> >
> > - Split get_patch_files() into get_patch_input_files() and
> > get_patch_output_files() to identify which files exist before and
> > after patch application.
> > - Filter out "/dev/null" from both to handle file creation/deletion
> > - Update refresh_patch() to only copy existing input files to the 'a'
> > directory and the resulting output files to the 'b' directory.
> >
> > This allows klp-build to successfully process patches that add or remove
> > source files.
> >
> > Signed-off-by: Joe Lawrence <[email protected]>
> > ---
> > scripts/livepatch/klp-build | 34 +++++++++++++++++++++++++++-------
> > 1 file changed, 27 insertions(+), 7 deletions(-)
> >
> > Lightly tested with patches that added or removed a source file, as
> > generated by `git diff`, `git format-patch`, and `diff -Nupr`.
> >
> > diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
> > index 9f1b77c2b2b7..5a99ff4c4729 100755
> > --- a/scripts/livepatch/klp-build
> > +++ b/scripts/livepatch/klp-build
> > @@ -299,15 +299,33 @@ set_kernelversion() {
> > sed -i "2i echo $localversion; exit 0" scripts/setlocalversion
> > }
> >
> > -get_patch_files() {
> > +get_patch_input_files() {
> > + local patch="$1"
> > +
> > + grep0 -E '^--- ' "$patch" \
> > + | gawk '{print $2}' \
> > + | grep -v '^/dev/null$' \
>
> Because pipefail is enabled, the grep0 helper should be used instead of
> grep, otherwise a failed match can propagate to an error. Maybe we need
> a "make check" or something which enforces that and runs shellcheck.
>
Good catch. So your idea is to drop a Makefile in scripts/livepatch
with a check target that runs shellcheck and then a klp-build specific
check for any non-grep0 grep? (like `grep -w 'grep' klp-build`). If
so, any other things to should check for?
--
Joe