[LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m

Li Wang li.wang@linux.dev
Mon Nov 9 04:36:27 CET 2026


> > +		for (p = name; (p = strchr(p, '-')); )
> > +			*p = '_';
> 
> Wouldn't it be easier to enforce the module names to have only
> underscores?

Good point.

> > +		if (!syscall(__NR_delete_module, name, O_NONBLOCK))
> > +			continue;
> > +
> > +		switch (errno) {
> > +		case ENOENT:		/* already unloaded */
> > +		case EWOULDBLOCK:	/* in use */
> > +		case EBUSY:		/* still loading or unloading */
> > +		case ENOSYS:		/* no CONFIG_MODULE_UNLOAD */
> > +			break;
> > +		default:
> > +			tst_res(TWARN | TERRNO, "Failed to unload module '%s'", name);
> > +		}

> Why not 'modprobe -r' the main difference is that 'modprobe -r' removes
> all unused depended modules. If anything loaded as a dependency of the
> module we loaded we are not going to be able to remove the module this
> way.

That was intentional. modprobe -r also removes unused dependencies,
including ones that were already loaded before the test. E.g. if can
is already loaded (but unused) and the test loads can-raw, then
'modprobe -r can-raw' removes both, i.e. cleanup would unload a module
the test did not load.

With delete_module() we remove only the module we loaded ourselves.
That always works, since dependencies do not hold a reference on the
module that uses them. The downside is that dependencies pulled in by
modprobe stay loaded after the test.

It's a trade-off: I'd rather leave a few extra modules loaded on the
SUT than remove modules that were there before the test started.

-- 
Regards,
Li Wang


More information about the ltp mailing list