[LTP] [PATCH v3 1/4] lib: add module is loaded check
Li Wang
li.wang@linux.dev
Wed Oct 14 05:18:27 CEST 2026
Hi Andrea,
> Hi Li,
>
> > +
> > +bool tst_module_is_loaded(const char *mod_name)
> > +{
> > + char line[4096];
> > + size_t mod_len = strlen(mod_name);
> > + FILE *file;
> > +
> > + file = fopen("/proc/modules", "r");
> > + if (!file)
> > + return false;
>
> why not using SAFE_FILE_LINES_SCANF() ?
file_lines_scanf() uses a fixed format string, and with
`arg_count == 0` (e.g. `"%s %*s"` with only suppressed
conversions) it cannot distinguish a matching line from a
non-matching one, because vsscanf returns 0 in both cases.
On top of that, /proc/modules needs to walk every line and
compare against a module name that is passed in at runtime
and may need the '-' to '_' normalization. So it is not a
good fit here; a plain fopen()/fgets() loop is clearer.
One more concern: /proc/modules may not exist at all on some
platforms. When the kernel is built with CONFIG_MODULES=n
there is no module support and /proc/modules is absent, and
some container runtimes also do not provide it. With that
would trigger tst_brkm(TBROK) and abort the test
--
Regards,
Li Wang
More information about the ltp
mailing list