]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
5 hours agotestsuite: Fix build warning on kernel 6.15 master
Lucas De Marchi [Mon, 7 Jul 2025 16:42:41 +0000 (11:42 -0500)] 
testsuite: Fix build warning on kernel 6.15

The module description is now required, otherwise a warning is emitted
by modpost:

WARNING: modpost: missing MODULE_DESCRIPTION() in mod-loop-k.o

Fix all of them with:

sed -i '/MODULE_LICENSE("LGPL");/a MODULE_DESCRIPTION("dummy test module");' testsuite/module-playground/mod-*.c
sed -i '/MODULE_LICENSE("GPL");/a MODULE_DESCRIPTION("dummy test module");' testsuite/module-playground/mod-simple.c

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 hours agoci: Use KDIR=any
Lucas De Marchi [Fri, 27 Jun 2025 17:13:12 +0000 (12:13 -0500)] 
ci: Use KDIR=any

Drop .github/print-kdir.sh and just use KDIR=any to handle the kernel
headers.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/384
6 hours agotestsuite: Handle KDIR=any
Lucas De Marchi [Fri, 27 Jun 2025 17:01:15 +0000 (12:01 -0500)] 
testsuite: Handle KDIR=any

I update my kernel frequently and may not be running a kernel with
headers installed. That always leads me to:

1) run `meson test -C build`
2) Oh, crap, it fails: no kernel headers
3) Find whatever kernel header is installed and point KDIR to it

We can do better and tell KDIR=any to use whatever it finds.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/384
7 hours agoutil: Use local variable in get_backoff_delta_msec
Tobias Stoeckmann [Sun, 29 Jun 2025 11:40:46 +0000 (13:40 +0200)] 
util: Use local variable in get_backoff_delta_msec

This might make the code easier to read.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
7 hours agomodprobe: return error on timeout
Tobias Stoeckmann [Thu, 19 Jun 2025 16:44:51 +0000 (18:44 +0200)] 
modprobe: return error on timeout

If module cannot be removed in time, return with a failure, not success:

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
7 hours agotestsuite: add test for get_backoff_delta_msec
Emil Velikov [Thu, 19 Jun 2025 16:41:22 +0000 (18:41 +0200)] 
testsuite: add test for get_backoff_delta_msec

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
7 hours agoutil: check for overflow in get_backoff_delta_msec
Tobias Stoeckmann [Sun, 29 Jun 2025 11:17:22 +0000 (13:17 +0200)] 
util: check for overflow in get_backoff_delta_msec

If a large delta is given, the multiplication might overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
7 hours agoutil: fix endless loop in get_backoff_delta_msec
Tobias Stoeckmann [Sun, 29 Jun 2025 11:13:34 +0000 (13:13 +0200)] 
util: fix endless loop in get_backoff_delta_msec

If current time t is already past tend, the while loop in
get_backoff_delta_msec never ends.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agoci: move compression variants further down
Emil Velikov [Mon, 16 Jun 2025 23:37:52 +0000 (00:37 +0100)] 
ci: move compression variants further down

Move the variants into their own section, similar to the moduledir and
co. This bears no functional change in the CI run.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/383
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agoci: remove default options from Debian/bullseye build
Emil Velikov [Mon, 16 Jun 2025 23:34:24 +0000 (00:34 +0100)] 
ci: remove default options from Debian/bullseye build

Both -Dopenssl=enabled and -Dtools=true are the default. Omit them from
the meson_setup.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/383
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agoci: 'temporary' disable sanitizers for 32bit builds
Emil Velikov [Mon, 16 Jun 2025 23:30:40 +0000 (00:30 +0100)] 
ci: 'temporary' disable sanitizers for 32bit builds

Currently running 32bit tests alongside sanitizers, segfaults due to our
syscall wrapper. Just disable the sanitizers, which means we get at
least some 32bit test coverage.

On a couple of attempts, I wasn't able to get a proper/robust solution,
as outlined in init_module.c - we need vsyscall() which does not exist.

Considering some distributions are dropping 32bit/i686 support, it may
be that we'll nuke these builds from CI sooner than later.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/383
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agoCONTRIBUTING.md: make it common markdown compatible
Emil Velikov [Sat, 21 Jun 2025 10:13:15 +0000 (11:13 +0100)] 
CONTRIBUTING.md: make it common markdown compatible

Adjust the markdown variant, so it renders correctly in both GitHub and
cgit (... vim also seems happier fwiw). AFAICT the latter is using
CommonMarkdown as handled by python-markdown.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/380
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agoREADME.md: make it common markdown compatible
Emil Velikov [Sat, 21 Jun 2025 10:09:50 +0000 (11:09 +0100)] 
README.md: make it common markdown compatible

Adjust the markdown variant, so it renders correctly in both GitHub and
cgit (... vim also seems happier fwiw). AFAICT the latter is using
CommonMarkdown as handled by python-markdown.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/380
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agotestsuite/test-modprobe: reinstate chdir error path
Emil Velikov [Fri, 20 Jun 2025 10:11:04 +0000 (11:11 +0100)] 
testsuite/test-modprobe: reinstate chdir error path

Earlier commit used a global sed to remove the no-longer needed
exit(EXIT_FAILURE) calls. In the process it also removed one instance
in the error path, which should remain.

Fixes: e09acf2e ("testsuite: remove exit from EXEC_TOOL tests")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/379
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 days agolibkmod/README: fix grammar
Tobias Stoeckmann [Thu, 19 Jun 2025 16:54:54 +0000 (18:54 +0200)] 
libkmod/README: fix grammar

Co-authored-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/378
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: remove exit() calls from main()
Emil Velikov [Fri, 13 Jun 2025 16:45:34 +0000 (17:45 +0100)] 
testsuite: remove exit() calls from main()

There is no particular reason for us to use exit(), so just avoid it.

As result, the only instances using of exit() are within the child
process and our cleanup is complete :-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: always exit() from the child process
Emil Velikov [Fri, 13 Jun 2025 16:45:34 +0000 (17:45 +0100)] 
testsuite: always exit() from the child process

Update the existing code-paths to always exit() for the child process.
We already handle that in a few places, but the error-paths are
(understandably) off.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: remove remaining exit/noreturn instances
Emil Velikov [Fri, 13 Jun 2025 16:37:25 +0000 (17:37 +0100)] 
testsuite: remove remaining exit/noreturn instances

Purge the remaining exit/noreturn instances, which means we now get a
consistent return path on all tests and across both success and failure
paths.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: remove exit from EXEC_TOOL tests
Emil Velikov [Fri, 13 Jun 2025 16:24:32 +0000 (17:24 +0100)] 
testsuite: remove exit from EXEC_TOOL tests

The EXEC_TOOL macros calls test_spawn_prog() which returns EXIT_FAILURE
in the unlikely case of a return from execv().

Thus the explicit exit() is dead code that we can remove and alongside
it the noreturn notation of the respective tests.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: introduce and use EXEC_TOOL() macro
Emil Velikov [Fri, 13 Jun 2025 16:16:09 +0000 (17:16 +0100)] 
testsuite: introduce and use EXEC_TOOL() macro

Swap the currect EXEC_DEPMOD and EXEC_MODPROBE with a slightly more
generic macro - EXEC_TOOL based off them.

Update all in-tree instances of test_spawn_prog() to use it.

This will make follow-up work (removing the noreturn/exit) a bit easier
and more consistent.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/test-remove: plug memory leaks in success path
Emil Velikov [Fri, 13 Jun 2025 19:12:28 +0000 (20:12 +0100)] 
testsuite/test-remove: plug memory leaks in success path

With the upcoming patches, removing exit() usage, ASan started reporting
that our test leaks kmod_module handles.

Resolve those leaks - we shouldn't be doing that in the normal (success)
path.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/test-init: plug memory leaks in success path
Emil Velikov [Fri, 13 Jun 2025 19:12:28 +0000 (20:12 +0100)] 
testsuite/test-init: plug memory leaks in success path

With the upcoming patches, removing exit() usage, ASan started reporting
that our test leaks kmod_module handles.

Resolve those leaks - we shouldn't be doing that in the normal (success)
path.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: use ARRAY_SIZE() for iteration
Emil Velikov [Fri, 13 Jun 2025 18:48:18 +0000 (19:48 +0100)] 
testsuite: use ARRAY_SIZE() for iteration

Currently we use a mix of ARRAY_SIZE() and iterator pointer, where the
latter needs an extra instance for the NULL sentinel. Plus as evidenced
by the EXIT_SUCCESS -> EXIT_FAILURE changes in test-new-module - is
error prone.

Consistently use ARRAY_SIZE(), fixing the logical error in the test
which was flagged by ASan as memory leak :-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: static const annotate the remaining test data
Emil Velikov [Fri, 13 Jun 2025 18:44:25 +0000 (19:44 +0100)] 
testsuite: static const annotate the remaining test data

A while ago we annotated a bunch of of the tests although I missed some
during grepping. Update the final instances, taking the chance to move
the strdup instances into the test loop and failing the test should the
duplication fails.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: --dry-run shouldn't need -v
Lucas De Marchi [Fri, 13 Jun 2025 19:11:08 +0000 (14:11 -0500)] 
tools/modprobe: --dry-run shouldn't need -v

Make sure it shows something when running in dry-run mode.

Before:
kmod $ lsmod | grep i915
kmod $ ./build/modprobe --dry-run i915
kmod $ ./build/modprobe -v --dry-run i915
insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst
insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst

After:
kmod $ lsmod | grep i915
kmod $ ./build/modprobe --dry-run i915
insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst
insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/372
3 weeks agotools/modprobe: Fix odd --remove-holders behavior
Lucas De Marchi [Fri, 13 Jun 2025 18:57:08 +0000 (13:57 -0500)] 
tools/modprobe: Fix odd --remove-holders behavior

--remove-holders was not implying --remove, which means that if the user
called `modprobe --remove-holders xe` it would actually try to insert
the xe module. Fix it and spell it out in the man page about one option
implying the other.

Considering i915 is not currently loaded:

Before:
kmod $ ./build/modprobe -v --dry-run --remove-holders i915
insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst
insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst
kmod $

After:
kmod $ ./build/modprobe -v --dry-run --remove-holders i915
kmod $

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/372
3 weeks agoman/modprobe.8: Remove needless **
Lucas De Marchi [Fri, 13 Jun 2025 17:45:31 +0000 (12:45 -0500)] 
man/modprobe.8: Remove needless **

There are 2 too many * to document the `-r` option.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/372
3 weeks agoci: remove Alpine -Ddocs=false WA
Emil Velikov [Mon, 16 Jun 2025 06:32:06 +0000 (07:32 +0100)] 
ci: remove Alpine -Ddocs=false WA

A while ago the Alpine gtk-doc tool chain was having issues building our
docs. That got resolved at some point over the past months, so we can
drop this local workaround.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/373
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: accept module name with --show-modversions
Emil Velikov [Mon, 19 May 2025 20:08:26 +0000 (21:08 +0100)] 
tools/modprobe: accept module name with --show-modversions

Use the newly introduced helper module_new_from_any(), so we accept both
files as well as modules. This means you can now do:
 - modprobe --show-modversions drm-vram-helper, alongside the existing
 - modprobe --show-modversions /full/path/to/the/module/drm_vram_helper.ko

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/modprobe: add modprobe --show-exports modulename
Emil Velikov [Fri, 30 May 2025 19:16:11 +0000 (20:16 +0100)] 
testsuite/modprobe: add modprobe --show-exports modulename

Add test for the newly introduced --show-exports code path.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/modprobe: remove --quiet from --show-{depends,exports}
Emil Velikov [Fri, 30 May 2025 19:10:09 +0000 (20:10 +0100)] 
testsuite/modprobe: remove --quiet from --show-{depends,exports}

Even though we don't give the user any feedback, the --quiet option is
only applicable with --remove. Remove it from any modprobe --show*
invocations.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: accept module name with --show-exports
Emil Velikov [Mon, 19 May 2025 20:08:26 +0000 (21:08 +0100)] 
tools/modprobe: accept module name with --show-exports

Use the newly introduced helper module_new_from_any(), so we accept both
files as well as modules. This means you can now do:
 - modprobe --show-exports drm-vram-helper, alongside the existing
 - modprobe --show-exports /full/path/to/the/module/drm_vram_helper.ko

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: factor out module_new_from_any()
Emil Velikov [Mon, 19 May 2025 19:54:33 +0000 (20:54 +0100)] 
tools/modprobe: factor out module_new_from_any()

Split the functionality into a helper function, which will be used with
later commits.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoman/modprobe.8: document --show-exports
Emil Velikov [Fri, 30 May 2025 18:23:04 +0000 (19:23 +0100)] 
man/modprobe.8: document --show-exports

The option was introduced a few years ago, yet the manual page went
without an update. Add some basic documentation.

Cc: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Fixes: 3ada8df8 ("modprobe: add --show-exports")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: standardize on --show-foo, deprecate the rest
Emil Velikov [Fri, 30 May 2025 18:11:48 +0000 (19:11 +0100)] 
tools/modprobe: standardize on --show-foo, deprecate the rest

Currently we have a range of options which show specific details,
although they vary in prefix or spelling:
 - prefix: dump vs resolve vs show
 - with and without dash after show

Converge on --show-foo and deprecate the rest. The old options are still
accepted but will throw a warning. Only the (new) consistent names are
listed in --help, while the manual page lists both but spells out that
the old ones will be removed.

To avoid any confusion with --show (aka --dry-run) the option is also
soft-deprecated.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: properly deprecate --remove-dependencies
Emil Velikov [Fri, 13 Jun 2025 15:34:22 +0000 (16:34 +0100)] 
tools/modprobe: properly deprecate --remove-dependencies

The option was annotated as deprecated a while ago, although we never
flagged a warning when it is in use.

Do that, remove it from the --help screen and add an explicit "will be
removed" notice in the manual page.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoman/modprobe.8: document --remove-holders
Emil Velikov [Fri, 30 May 2025 18:23:04 +0000 (19:23 +0100)] 
man/modprobe.8: document --remove-holders

The option was introduced a few years ago, yet the manual page went
without an update. Add some basic documentation.

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Fixes: 42b32d30 ("modprobe: Fix holders removal")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/static-nodes: don't use %m on mkdir_parents() failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
tools/static-nodes: don't use %m on mkdir_parents() failure

The function returns the error code itself, so we should be using
strerror(-err) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/depmod: don't use %m on kmod_new() failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
tools/depmod: don't use %m on kmod_new() failure

The KMOD API returns NULL on error and getting the exact means why it
failed is undefined. In practise the errno is set in _some_ of the error
paths, but not all.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/depmod: don't use %m on mkdir_p() failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
tools/depmod: don't use %m on mkdir_p() failure

The function returns the error code itself, so we should be using
strerror(-err) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/depmod: explicitly return ENOMEM on hash_new() failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
tools/depmod: explicitly return ENOMEM on hash_new() failure

The function will always set errno of ENOMEM, so we might as well use
that. Making the code more consistent and removing a few bytes/LoC.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/test-{init,remove}: don't use %m with kmod API
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
testsuite/test-{init,remove}: don't use %m with kmod API

The kmod API returns the error code directly, which one should be used
alongside strerror(). Using %m may return a different result all
together.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: don't use %m on read_str_ulong() failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
libkmod: don't use %m on read_str_ulong() failure

The function returns the actual error itself, identically to the signed
variant - read_str_long(). Unlike the signed variant, one of ulong's
users incorrectly uses %m instead of strerror(-err).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: don't use %m on strbuf_to_vector() failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
libkmod: don't use %m on strbuf_to_vector() failure

The function does not set the errno on overflow conditions, so the ERR()
will produce (somewhat) arbitrary strerror. Similar to other places
throughout the code base - just use ENOMEM.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: readback errno before calling kmod_log()
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
libkmod: readback errno before calling kmod_log()

Majority of our code-base reads back errno before calling the kmod_log()
to print an error, info or debug message.

Correct the last instances for consistency sake.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: explicitly return ENOMEM on kmod_module_*_new failure
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
libkmod: explicitly return ENOMEM on kmod_module_*_new failure

All these functions do is malloc() the respective struct and initialize
the members. The errno can only be ENOMEM, so just return it directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoUse explicit ENOMEM when {m,re}alloc fails
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
Use explicit ENOMEM when {m,re}alloc fails

Currently our codebase has a mix of explicitly using ENOMEM and
propagating the errno... The latter of which is guaranteed to be ENOMEM
as documented in the manual pages.

Consolidate on ENOMEM, both for consistency sake and to remove a few
bytes off our binaries ;-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: return ENOMEM when strbuf_pushchar(s) fails
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
libkmod: return ENOMEM when strbuf_pushchar(s) fails

Currently get_strings() assumes that errno is set when either function
fails. This is not the case when our overflow checks kick in. The other
case where these functions fail is memory exhaustion.

In practice we cannot do anything if either of those trigger, plus I
don't see a compelling reason to set errno to EOVERFLOW... Something
which other parts of the codebase don't do.

So let's just return ENOMEM and avoid the corner case of returning
success from get_strings(), when it should be failing.

Fixes: 1005e99e ("libkmod: refactor builtin module handling")
Fixes: 952bf223 ("strbuf: Add strbuf_reserve_extra()")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoRemove unused errno.h include
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)] 
Remove unused errno.h include

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/test-util: add extra get_backoff_delta_msec iteration
Emil Velikov [Fri, 30 May 2025 10:21:32 +0000 (11:21 +0100)] 
testsuite/test-util: add extra get_backoff_delta_msec iteration

Add an extra test to check delta does not exceed the upper boundary.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoshared/util: remove unused t0 in get_backoff_delta_msec()
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
shared/util: remove unused t0 in get_backoff_delta_msec()

The argument was unused ever since the function was introduced - remove
it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/static-nodes: silence unused parameter warning
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
tools/static-nodes: silence unused parameter warning

The function signature for our printers is uniform, even though in one
of the instances a parameter is unused. There is not much we can do
here, just silence the compiler warning.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/modprobe: initialize msec variables as needed
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
tools/modprobe: initialize msec variables as needed

Remove the initialization for interval_msec and tend_msec. They are set
on the first iteration... Assuming the user has set non-zero wait time.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/kmod: silence unused parameter warnings
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
tools/kmod: silence unused parameter warnings

kmod_help() does not use neither argc nor argv although due to the
dispatch mechanism they are part of the function signature.

Not much we can do here - silence the compiler warnings.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotools/depmod: remove unused parameter struct depmod
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
tools/depmod: remove unused parameter struct depmod

In a handful of functions we don't need the depmod struct. Remove it,
making the compiler happy and shaving a few bytes off the resulting
binary.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/test-hash: silence unused parameter warning
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
testsuite/test-hash: silence unused parameter warning

The implementation of our "hash_free" function varies in that the hash
data itself is not freed. Thus the function argument is unused, leading
to annoying compiler warning. Since there is nothing to be done here,
just silence it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/{init,delete}_module: add TODOs for args validation
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
testsuite/{init,delete}_module: add TODOs for args validation

Currently we pass arguments to our *_module wrappers, which are lacking
any validation. Add a few TODO notes and silence the unused argument
compiler warnings.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite/init_module: remove unused argument
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
testsuite/init_module: remove unused argument

Ever since write_one_line_file() was introduced, it never really
used its len argument. It's dead code, so just remove it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: remove unused parameters
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
testsuite: remove unused parameters

As of previous commit, neither fd_cmp_regex nor fd_cmp_exact needs the
test fixture. Remove the unused parameter and make the compiler happy
;-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: remove unused struct test::print_outputs
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
testsuite: remove unused struct test::print_outputs

None of our tests use it, plus it's inconsistently handled - plain
comparison honours it, regex comparison does not.

In addition, on test failure the expected/actual values are always
printed. So we're not missing anything (too) critical here.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agotestsuite: stop passing struct test to the test itself
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
testsuite: stop passing struct test to the test itself

None of our tests require the test fixture details. Stop passing it into
the test function itself.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: silence unused param warnings for kmod_file_load_*() stubs
Emil Velikov [Fri, 30 May 2025 10:52:27 +0000 (11:52 +0100)] 
libkmod: silence unused param warnings for kmod_file_load_*() stubs

When building without compression, the respective load functions are
static inline header stubs. In which case the struct kmod_file *file is
always unused and the compiler rightfully warns about it.

Not much we can do here, other than annotate them to silence the
warnings.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agolibkmod: add TODO for module hashkey handling
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)] 
libkmod: add TODO for module hashkey handling

We currently "leak" the hashkey handling in a few places. As result we
ignore the name passed to kmod_module_new().

Add a TODO entry and silence the unused parameter compiler warning.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoshared: properly __attribute__ all macros
Emil Velikov [Fri, 30 May 2025 10:00:13 +0000 (11:00 +0100)] 
shared: properly __attribute__ all macros

Handful of the attributes were missing the trailing double underscore.
Thus they were not picked by our git grep combo and ultimately missing
from .clang-format.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoshared/macro: avoid nesting macros where possible
Emil Velikov [Tue, 3 Jun 2025 18:00:49 +0000 (19:00 +0100)] 
shared/macro: avoid nesting macros where possible

Always try to use the attribute notation, so that we can reliably
collect all the macros in our .clang-format.

In the process, we can remove some (no longer used) macros.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 weeks agoclang-format: update attribute macros
Emil Velikov [Tue, 3 Jun 2025 17:55:03 +0000 (18:55 +0100)] 
clang-format: update attribute macros

Use the command to update the attribute macros list. Seemingly we've
updated the list manually, which meant that a) some symbols were not
annotated the expected way and b) some macros were not picked up.

First we start with auto-generating the list, the other issues will be
handled as follow-ups.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 weeks agoci: fold gcc/clang combinations together
Emil Velikov [Tue, 3 Jun 2025 21:46:48 +0000 (22:46 +0100)] 
ci: fold gcc/clang combinations together

Instead of listing each combination on per-compiler basis, assume we
want both unless annotated otherwise.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/362
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 weeks agoci: fold 32 and 64 bit jobs together
Emil Velikov [Tue, 3 Jun 2025 21:46:48 +0000 (22:46 +0100)] 
ci: fold 32 and 64 bit jobs together

We currently construct a single container for each distro, which is
capable of running both 32 and 64 bit builds.

In addition, since we're meson only (which allows only out-of-tree
builds) we can do multiple builds for a given checkout.

As result we hammer the docker registry and distribution/package servers
a bit less.

Notes:
 - 32bit distcheck is disabled - not particularly interesting
 - 32bit tests are disabled for everyone - they are consistently failing

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/362
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 weeks agoci: install and use bash across the board
Emil Velikov [Tue, 3 Jun 2025 22:06:48 +0000 (23:06 +0100)] 
ci: install and use bash across the board

The upcoming CI rework will hard depend on some bash constructs. While
theoretically possible to make them dash compliant, I'm not sure it's
worth the effort. Just install bash and carry on.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/362
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 weeks agoci: use meson bla -C builddir/
Emil Velikov [Tue, 3 Jun 2025 21:46:47 +0000 (22:46 +0100)] 
ci: use meson bla -C builddir/

Use builddir/ as indicated in our README, which makes it obvious that
what the argument is. While there, remove a few instances of mkdir/cd -
meson and ninja can handle it themselves.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/362
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 weeks agoscripts/sanitizer-env.sh: remove incorrect $CC quotes
Emil Velikov [Fri, 23 May 2025 11:01:29 +0000 (12:01 +0100)] 
scripts/sanitizer-env.sh: remove incorrect $CC quotes

On Arch (at least) the shell chokes when the CC variable contains space,
for the given construct - $("$CC" foobar).

Since we variable is likely to contain the executable and arguments, the
quotation is wrong. Drop it and ultimately resolve the LD_PRELOAD
issues... That said, the tests still fail over here, segfault-ing in (or
due to) the LD_PRELOAD library init-modules.so.

Fixes: f5b4ff82 ("Add support for clang sanitizers")
Fixes: c7686797 ("scripts/sanitizer-env.sh: support new clang 19 DSO")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/365
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoci: bump the all-actions group with 2 updates
dependabot[bot] [Sun, 1 Jun 2025 01:46:06 +0000 (01:46 +0000)] 
ci: bump the all-actions group with 2 updates

Bumps the all-actions group with 2 updates: [github/codeql-action](https://github.com/github/codeql-action) and [codecov/codecov-action](https://github.com/codecov/codecov-action).

Updates `github/codeql-action` from 3.28.16 to 3.28.18
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/28deaeda66b76a05916b6923827895f2b14ab387...ff0a06e83cb2de871e5a09832bc6a81e7276941f)

Updates `codecov/codecov-action` from 5.4.2 to 5.4.3
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/ad3126e916f78f00edff4ed0317cf185271ccc2d...18283e04ce6e62d37312384ff67231eb8fd56d24)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: codecov/codecov-action
  dependency-version: 5.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Link: https://github.com/kmod-project/kmod/pull/366
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotools/depmod: use nsec granularity when checking timestamps
Emil Velikov [Sat, 24 May 2025 15:10:11 +0000 (16:10 +0100)] 
tools/depmod: use nsec granularity when checking timestamps

Current code uses the POSIX.1-2001 stat::st_mtime which has one second
granularity. Considering the depmod execution time may be smaller, we
should be using the POSIX.1-2008 stat::st_mtim which has nano-second
granularity instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/359
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoRemove dietlibc stat::st_mtim workaround
Emil Velikov [Sat, 24 May 2025 14:40:49 +0000 (15:40 +0100)] 
Remove dietlibc stat::st_mtim workaround

Some versions of dietlibc lack struct stat::st_mtim, which was
introduced with POSIX.1-2008.

Considering the slow development cycle of dietlibc (last three releases
are 2024, 2018 and 2013) and there's no popular user (nor one in CI) of
it, let's remove the workaround.

All the other runtimes that we target - glibc, bionic and musl - have
the struct member.

Iff needed we can reintroduce the workaround at a later stage alongside
a CI permutation.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/359
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoREADME: update C runtime library section
Emil Velikov [Thu, 29 May 2025 09:26:29 +0000 (10:26 +0100)] 
README: update C runtime library section

Our readme lists uClibc which has been EOL for over a decade and
superseded by uClibc-ng. In addition, in one place our code-base tries
to support dietlibc for some pre POSIX.1-2008 functionality.

Explicitly list POSIX.1-2008 alongside the C runtime libraries, which
are known to work.

If your favourite C library does not work with kmod, feel free to send
us patches - plus ideally one which adds a CI action for us to test.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/359
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoREADME: explicitly document compiler requirements
Emil Velikov [Thu, 29 May 2025 09:21:47 +0000 (10:21 +0100)] 
README: explicitly document compiler requirements

Document C11 + GNU extensions as the requirement, omitting the exact
list of extensions since it's quite a bit.

The minimum compiler versions are somewhat arbitrary - we don't check
for them, so your experience may vary. Patches to update the README, or
to make kmod more widely buildable are welcome.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/359
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoscripts/setup-modules.sh: remove autotools w/a
Emil Velikov [Sat, 24 May 2025 16:22:27 +0000 (17:22 +0100)] 
scripts/setup-modules.sh: remove autotools w/a

With autotools one can do in and out of tree builds. Since we're meson
only these days, we can drop the in-tree path.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/356
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoConvert most #ifdef HAVE_FOO checks to #if HAVE_FOO
Emil Velikov [Sat, 24 May 2025 15:21:18 +0000 (16:21 +0100)] 
Convert most #ifdef HAVE_FOO checks to #if HAVE_FOO

The former is somewhat error prone, since the pre-processor will
evaluate the presence of the define, which might have been omitted due
to wrong include or otherwise.

Swap for the other solution we already have in-tree - always set the
relevant define(s) and evaluate them numerically. That combined with
-Wundef means that we'll get meaningful compiler warning when we get
something wrong.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/356
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agocheck strtol/strtoul/strtoull results
Tobias Stoeckmann [Sun, 25 May 2025 08:22:09 +0000 (10:22 +0200)] 
check strtol/strtoul/strtoull results

The strto* family of functions may fail if the input string contains
a number which is too large for the designated data type. In such
cases, errno is set to ERANGE. Check for this error condition and if
subsequent casts would truncate the value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/357
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoRemove default initializer for static variables
Emil Velikov [Thu, 29 May 2025 08:30:58 +0000 (09:30 +0100)] 
Remove default initializer for static variables

The spec dictates that static variables are initialized to 0/NULL.
Remove the unnecessary explicit initialization - on older compilers this
sheds a few bytes off the data section of respective binaries.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agolibkmod: s/* const/*const/ style nitpick
Emil Velikov [Sat, 24 May 2025 18:18:27 +0000 (19:18 +0100)] 
libkmod: s/* const/*const/ style nitpick

Portion of the header is annotated as clang-format off, to prevent
unwanted over formatting by clang. At the same time, a few erroneous
spaces slipped in.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotools: move a few more symbols to data.rel.ro
Emil Velikov [Sat, 24 May 2025 18:17:24 +0000 (19:17 +0100)] 
tools: move a few more symbols to data.rel.ro

Annotate the arrays (not the data) as constant, so the compiler can
store it in the RO segment.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoshared: declare DECLARE_(DL,PTR)SYM as static
Emil Velikov [Sat, 24 May 2025 18:09:06 +0000 (19:09 +0100)] 
shared: declare DECLARE_(DL,PTR)SYM as static

Declare the symbol pointers as static, otherwise the compiler will add
them to the data section instead of bss.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotools/depmod: remove set but unused timeval
Emil Velikov [Sat, 24 May 2025 15:03:08 +0000 (16:03 +0100)] 
tools/depmod: remove set but unused timeval

No longer needed since the introduction of tmpfile-util.

Fixes: aae48bc9 ("depmod: add tmpfile-util to generate temporary file")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotestsuite/path: defer and inline get_rootpath()
Emil Velikov [Sat, 24 May 2025 12:23:09 +0000 (13:23 +0100)] 
testsuite/path: defer and inline get_rootpath()

In a handful of use-cases, we don't need to trap the respective libc
function. Although at that point we have already fetched the rootfs
environment variable.

Defer it until it's needed and in the process inline the function. As
result we have a) less duplication in the wrappers and b) the rootpath
handling is no longer split across multiple functions.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/355
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotestsuite/path: defer dlsym() until needed
Emil Velikov [Sat, 24 May 2025 12:10:50 +0000 (13:10 +0100)] 
testsuite/path: defer dlsym() until needed

There is no point in fetching the symbol if we already know we don't
need it. Defer the get_libc_func() after get_rootpath() and trap_path().

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/355
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotestsuite/path: cache the old dlsym() results
Emil Velikov [Sat, 24 May 2025 12:02:48 +0000 (13:02 +0100)] 
testsuite/path: cache the old dlsym() results

There is no need for us to repeatedly fetch the respective symbols.
Based on the static storage of _fn, this must have been the goal since
day 1.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/355
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotestsuite: fprintf() + abort() when dlsym() returns NULL
Emil Velikov [Sat, 24 May 2025 11:57:11 +0000 (12:57 +0100)] 
testsuite: fprintf() + abort() when dlsym() returns NULL

Currently each of our three dlsym() instances behaves differently. From
seg-faulting, to abort() to assert(). Just use abort throughout, since
assert() is no-op when NDEBUG is defined.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/355
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotestsuite: always use dlsym(RTLD_NEXT, ...)
Emil Velikov [Sat, 24 May 2025 11:50:15 +0000 (12:50 +0100)] 
testsuite: always use dlsym(RTLD_NEXT, ...)

It has been supported by glibc, musl and bionic for years - our
supported platforms.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/355
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agolibkmod: use strstartswith() over memcmp()
Emil Velikov [Sat, 24 May 2025 11:33:36 +0000 (12:33 +0100)] 
libkmod: use strstartswith() over memcmp()

In the cases where we have a string literal, we can use our helper
without adding performance overhead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotools: use strlen() for string literals
Emil Velikov [Sat, 24 May 2025 11:06:13 +0000 (12:06 +0100)] 
tools: use strlen() for string literals

Older compilers had struggles expanding strlen(string-literal) to a
constant compile time expression. Thus our code-base used sizeof() - 1
instead.

This has been resolved for years, so let's use the correct function.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agoshared: use strlen() for string literals
Emil Velikov [Sat, 24 May 2025 11:06:13 +0000 (12:06 +0100)] 
shared: use strlen() for string literals

Older compilers had struggles expanding strlen(string-literal) to a
constant compile time expression. Thus our code-base used sizeof() - 1
instead.

This has been resolved for years, so let's use the correct function.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agolibkmod: use strlen() for string literals
Emil Velikov [Sat, 24 May 2025 11:06:13 +0000 (12:06 +0100)] 
libkmod: use strlen() for string literals

Older compilers had struggles expanding strlen(string-literal) to a
constant compile time expression. Thus our code-base used sizeof() - 1
instead.

This has been resolved for years, so let's use the correct function. As
a bonus point, we can remove a few variable making the code tad easier
to follow.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agolibkmod: reuse streq/strstartswith() whenever possible
Emil Velikov [Fri, 23 May 2025 13:15:36 +0000 (14:15 +0100)] 
libkmod: reuse streq/strstartswith() whenever possible

Use our handy macro(s) for clarity and consistency sake.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agolibkmod: reuse strstartswith() whenever possible
Emil Velikov [Fri, 23 May 2025 13:15:36 +0000 (14:15 +0100)] 
libkmod: reuse strstartswith() whenever possible

Use our handy macro(s) for clarity and consistency sake.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agotestsuite: reuse streq() whenever possible
Emil Velikov [Fri, 23 May 2025 13:15:36 +0000 (14:15 +0100)] 
testsuite: reuse streq() whenever possible

Use our handy macro(s) for clarity and consistency sake.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agomeson: disable Wdeclaration-after-statement
Emil Velikov [Sat, 24 May 2025 16:40:47 +0000 (17:40 +0100)] 
meson: disable Wdeclaration-after-statement

Having declarations after statement is a C90 requirement, which was
relaxed with C99. While there are some arguments for having it enabled
in new code, there are benefits to the contrary which are more appealing
IMHO.

Namely, by keeping the declarations where the variables are used, better
outlines the scope, reduces chances of shadowing and helps us avoid
"unused variable" compiler warning in some paths.

Flip the warning to -Wno for now and future patches can remove some of
the workarounds we have in-tree.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/360
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 weeks agomeson: alpha sort -Wno section
Emil Velikov [Thu, 29 May 2025 09:53:12 +0000 (10:53 +0100)] 
meson: alpha sort -Wno section

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/360
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 weeks agotestsuite: modprobe: Add --force-{vermagic,modversion} tests
Rong Tao [Tue, 6 May 2025 10:57:17 +0000 (18:57 +0800)] 
testsuite: modprobe: Add --force-{vermagic,modversion} tests

We don't have any moversion/vermagic tests. This patch add testsuite
--force-{vermagic,modversion} for modprobe.

Link: https://github.com/kmod-project/kmod/pull/344
Signed-off-by: Rong Tao <rongtao@cestc.cn>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 weeks agolibkmod: update remaining function to return the error code
Emil Velikov [Wed, 7 May 2025 17:58:11 +0000 (18:58 +0100)] 
libkmod: update remaining function to return the error code

Rework the function signature and return the error code instead of the
stripped module. Thus we no longer explicitly set errno.

v2:
 - kmod_file_open() - use _cleanup_free_, return errno instead of ENOMEM

Reference: https://github.com/kmod-project/kmod/issues/244
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/346
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>