Re: [PATCH] Fix implicit cast warning in test_klp_state.c

Joe Lawrence
2024-02-21T18:27:04Z

On 2/21/24 07:44, Nicolai Stange wrote:
> Shresth Prasad <shresthprasad7@gmail.com> writes:
>
>> I checked the source code and yes I am on the latest Linux next repo.
>>
>> Here's the warning:
>> /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:38:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
>>    38 |         loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE);
>>       |                        ^
>
>
> Is the declaration of klp_get_state() visible at that point, i.e. is
> there perhaps any warning about missing declarations above that?
>
> Otherwise C rules would default to assume an 'int' return type.
>

This is an interesting clue. I thought I might be able to reproduce the
build error by modifying include/livepatch.h and running `make -j15 -C
tools/testing/selftests/livepatch` ... but that seemed to work fine on
my system. I even removed the entire include/ subdir from my tree and
it still built the test module. Huh?

Then I moved /lib/modules/$(uname -r)/build out of the way and saw that
the compilation failed. Ah hah -- that's right, it's using the system
build tree. That version of livepatch.h may have a missing or
completely different definition of klp_get_state().

How does this sequence work for you, Shresth:

# Verify that kernel livepatching is turned on
$ grep LIVEPATCH .config
CONFIG_HAVE_LIVEPATCH=y
CONFIG_LIVEPATCH=y

# Build linux-next kernel tree and then the livepatch selftests,
# pointing KDIR to this tree
$ make -j$(nproc) vmlinux && \
make -j$(nproc) KDIR=$(pwd) -C tools/testing/selftests/livepatch

--
Joe