On Wed, Nov 20, 2024 at 8:57 AM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote: > > The generic ->do_entry() handler is currently limited to returning > a single alias string. > > However, this is not flexible enough for several subsystems, which > currently require their own implementations: > > - do_usb_table() > - do_of_table() > - do_pnp_device_entry() > - do_pnp_card_entries() > > This commit introduces a helper function so that these special cases can > add multiple MODULE_ALIAS() and then migrate to the generic framework. > > Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx> > --- > > scripts/mod/file2alias.c | 89 +++++++++++++++++++++++++++++----------- > scripts/mod/modpost.c | 11 ++++- > scripts/mod/modpost.h | 19 ++++++++- > 3 files changed, 91 insertions(+), 28 deletions(-) > > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c > index 34678ed40fdb..e31619cee05e 100644 > --- a/scripts/mod/file2alias.c > +++ b/scripts/mod/file2alias.c > @@ -10,6 +10,12 @@ > * of the GNU General Public License, incorporated herein by reference. > */ > > +#include <stdarg.h> > +#include <stdio.h> > + > +#include "list.h" > +#include "xalloc.h" > + > #include "modpost.h" > #include "devicetable-offsets.h" > > @@ -31,6 +37,56 @@ typedef Elf64_Addr kernel_ulong_t; > #include <ctype.h> > #include <stdbool.h> > > +/** > + * module_alias_printf - add auto-generated MODULE_ALIAS() > + * > + * @mod: module > + * @append_wildcard: append '*' for future extension if not exist yet > + * @fmt: printf(3)-like format > + */ > +static void __attribute__((format (printf, 3, 4))) > +module_alias_printf(struct module *mod, bool append_wildcard, > + const char *fmt, ...) > +{ > + struct module_alias *new; > + size_t len, n; > + va_list ap; > + > + /* Determine required size. */ > + va_start(ap, fmt); > + n = vsnprintf(NULL, 0, fmt, ap); > + va_end(ap); > + > + if (n < 0) { > + error("vsnprintf failed\n"); > + return; > + } > + > + len = n + 1; /* extra byte for '\0' */ > + > + if (append_wildcard) > + len++; /* extra byte for '*' */ > + > + new = xmalloc(sizeof(*new) + len); > + > + /* Now, really print it to the allocated buffer */ > + va_start(ap, fmt); > + n = vsnprintf(new->str, len, fmt, ap); > + va_end(ap); > + > + if (n < 0) { > + error("vsnprintf failed\n"); > + return; This is a memory leak bug. I will add free() here. if (n < 0) { error("vsnprintf failed\n"); + free(new); return; } -- Best Regards Masahiro Yamada