Skip to content

Commit a62c12b

Browse files
committed
depinfo: Add support of weakdeps
Weak dependencies are similar to "pre softdep" and are also optional, but unlike them kmod will not load such modules. Such dependencies are intended to indicate optional dependencies between modules. Link: https://politreco.com/2024/08/linux-module-dependencies/ Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=61842868de13aa7fd7391c626e889f4d6f1450bf Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
1 parent 6a466de commit a62c12b

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

utils/depinfo/kmod-depinfo.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,41 +352,45 @@ static int
352352
depinfo_alias(struct kmod_ctx *ctx, const char *alias, enum alias_need req);
353353

354354
static int
355-
process_depends(struct kmod_ctx *ctx, const char *depends)
355+
__process_depends(struct kmod_ctx *ctx, const char *depends, const char *delim, enum alias_need req)
356356
{
357357
int ret = 0;
358358
char *s, *str, *token, *saveptr = NULL;
359359
s = str = strdup(depends);
360360

361-
while ((token = strtok_r(str, ",", &saveptr)) != NULL) {
362-
if (depinfo_alias(ctx, token, ALIAS_REQUIRED) < 0)
361+
while ((token = strtok_r(str, delim, &saveptr)) != NULL) {
362+
if (depinfo_alias(ctx, token, req) < 0)
363363
ret = -1;
364364
str = NULL;
365365
}
366366
free(s);
367367
return ret;
368368
}
369369

370+
371+
static int
372+
process_depends(struct kmod_ctx *ctx, const char *depends)
373+
{
374+
return __process_depends(ctx, depends, ",", ALIAS_REQUIRED);
375+
}
376+
370377
static int
371378
process_soft_depends(struct kmod_ctx *ctx, const char *depends)
372379
{
373-
int ret = 0;
374-
char *s, *str, *token, *saveptr = NULL;
375380
size_t len = strlen(depends);
376-
s = str = strdup(depends);
377381

378-
if (len > 5 && !strncmp("pre: ", s, 5))
379-
str += 5;
380-
else if (len > 6 && !strncmp("post: ", s, 6))
381-
str += 6;
382+
if (len > 5 && !strncmp("pre: ", depends, 5))
383+
depends += 5;
384+
else if (len > 6 && !strncmp("post: ", depends, 6))
385+
depends += 6;
382386

383-
while ((token = strtok_r(str, " ", &saveptr)) != NULL) {
384-
if (depinfo_alias(ctx, token, ALIAS_OPTIONAL) < 0)
385-
ret = -1;
386-
str = NULL;
387-
}
388-
free(s);
389-
return ret;
387+
return __process_depends(ctx, depends, " ", ALIAS_OPTIONAL);
388+
}
389+
390+
static int
391+
process_weak_depends(struct kmod_ctx *ctx, const char *depends)
392+
{
393+
return __process_depends(ctx, depends, " ", ALIAS_OPTIONAL);
390394
}
391395

392396
static int
@@ -440,6 +444,9 @@ depinfo(struct kmod_ctx *ctx, struct kmod_module *mod)
440444
} else if (!strcmp("softdep", key)) {
441445
if (process_soft_depends(ctx, val) < 0)
442446
ret = -1;
447+
} else if (!strcmp("weakdep", key)) {
448+
if (process_weak_depends(ctx, val) < 0)
449+
ret = -1;
443450
}
444451
}
445452
if ((opts & SHOW_FIRMWARE) && !strcmp("firmware", key))

0 commit comments

Comments
 (0)