Skip to content

Commit

Permalink
depinfo: Add support of weakdeps
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
legionus committed Aug 14, 2024
1 parent 6a466de commit a62c12b
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions utils/depinfo/kmod-depinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,41 +352,45 @@ static int
depinfo_alias(struct kmod_ctx *ctx, const char *alias, enum alias_need req);

static int
process_depends(struct kmod_ctx *ctx, const char *depends)
__process_depends(struct kmod_ctx *ctx, const char *depends, const char *delim, enum alias_need req)
{
int ret = 0;
char *s, *str, *token, *saveptr = NULL;
s = str = strdup(depends);

while ((token = strtok_r(str, ",", &saveptr)) != NULL) {
if (depinfo_alias(ctx, token, ALIAS_REQUIRED) < 0)
while ((token = strtok_r(str, delim, &saveptr)) != NULL) {
if (depinfo_alias(ctx, token, req) < 0)
ret = -1;
str = NULL;
}
free(s);
return ret;
}


static int
process_depends(struct kmod_ctx *ctx, const char *depends)
{
return __process_depends(ctx, depends, ",", ALIAS_REQUIRED);
}

static int
process_soft_depends(struct kmod_ctx *ctx, const char *depends)
{
int ret = 0;
char *s, *str, *token, *saveptr = NULL;
size_t len = strlen(depends);
s = str = strdup(depends);

if (len > 5 && !strncmp("pre: ", s, 5))
str += 5;
else if (len > 6 && !strncmp("post: ", s, 6))
str += 6;
if (len > 5 && !strncmp("pre: ", depends, 5))
depends += 5;
else if (len > 6 && !strncmp("post: ", depends, 6))
depends += 6;

while ((token = strtok_r(str, " ", &saveptr)) != NULL) {
if (depinfo_alias(ctx, token, ALIAS_OPTIONAL) < 0)
ret = -1;
str = NULL;
}
free(s);
return ret;
return __process_depends(ctx, depends, " ", ALIAS_OPTIONAL);
}

static int
process_weak_depends(struct kmod_ctx *ctx, const char *depends)
{
return __process_depends(ctx, depends, " ", ALIAS_OPTIONAL);
}

static int
Expand Down Expand Up @@ -440,6 +444,9 @@ depinfo(struct kmod_ctx *ctx, struct kmod_module *mod)
} else if (!strcmp("softdep", key)) {
if (process_soft_depends(ctx, val) < 0)
ret = -1;
} else if (!strcmp("weakdep", key)) {
if (process_weak_depends(ctx, val) < 0)
ret = -1;
}
}
if ((opts & SHOW_FIRMWARE) && !strcmp("firmware", key))
Expand Down

0 comments on commit a62c12b

Please sign in to comment.