Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libkmod: Simplify lookup_builtin_file() #233

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ CC_CHECK_FLAGS_APPEND(with_cflags, [CFLAGS], [\
-Wmissing-noreturn \
-Wmissing-prototypes \
-Wnested-externs \
-Wno-attributes=clang::suppress \
-Wno-unused-parameter \
-Wold-style-definition \
-Wpointer-arith \
Expand Down
2 changes: 1 addition & 1 deletion libkmod/libkmod-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static int kmod_config_add_blacklist(struct kmod_config *config, const char *mod

DBG(config->ctx, "modname=%s\n", modname);

p = strdup(modname);
_clang_suppress_alloc_ p = strdup(modname);
if (!p)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion libkmod/libkmod-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ static int module_do_install_commands(struct kmod_module *mod, const char *optio
size_t suffixlen = cmdlen - prefixlen - varlen;
size_t slen = cmdlen - varlen + options_len;
char *suffix = p + varlen;
char *s = malloc(slen + 1);
_clang_suppress_alloc_ char *s = malloc(slen + 1);
if (!s)
return -ENOMEM;

Expand Down
6 changes: 2 additions & 4 deletions libkmod/libkmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,9 @@ static char *lookup_file(struct kmod_ctx *ctx, enum kmod_index index_number,

static bool lookup_builtin_file(struct kmod_ctx *ctx, const char *name)
{
char *line = lookup_file(ctx, KMOD_INDEX_MODULES_BUILTIN, name);
bool found = line != NULL;
_cleanup_free_ char *line = lookup_file(ctx, KMOD_INDEX_MODULES_BUILTIN, name);

free(line);
return found;
return line;
}

int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char *name,
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ add_project_arguments(
'-Wmissing-prototypes',
'-Wnested-externs',
'-Wno-unused-parameter',
'-Wno-attributes=clang::suppress',
'-Wold-style-definition',
'-Wpointer-arith',
'-Wredundant-decls',
Expand Down
18 changes: 17 additions & 1 deletion shared/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,26 @@
#define _must_check_ __attribute__((warn_unused_result))
#define _printf_format_(a, b) __attribute__((format(printf, a, b)))
#define _always_inline_ __inline__ __attribute__((always_inline))
#define _cleanup_(x) __attribute__((cleanup(x)))

#if defined(__clang_analyzer__)
#define _clang_suppress_ __attribute__((suppress))
#define _clang_suppress_alloc_ __attribute__((suppress))
#else
#define _clang_suppress_
#define _clang_suppress_alloc_
#endif

#define _nonnull_(...) __attribute__((nonnull(__VA_ARGS__)))
#define _nonnull_all_ __attribute__((nonnull))

#define _cleanup_(x) _clang_suppress_alloc_ __attribute__((cleanup(x)))

static inline void freep(void *p)
{
free(*(void **)p);
}
#define _cleanup_free_ _cleanup_(freep)

/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
* compiler versions */
#ifndef noreturn
Expand Down
2 changes: 1 addition & 1 deletion shared/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ int mkdir_p(const char *path, int len, mode_t mode)
_cleanup_free_ char *start;
char *end;

start = memdup(path, len + 1);
_clang_suppress_alloc_ start = memdup(path, len + 1);
if (!start)
return -ENOMEM;

Expand Down
5 changes: 0 additions & 5 deletions shared/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)

/* misc */
/* ************************************************************************ */
static inline void freep(void *p)
{
free(*(void **)p);
}
#define _cleanup_free_ _cleanup_(freep)

static inline bool uadd32_overflow(uint32_t a, uint32_t b, uint32_t *res)
{
Expand Down
5 changes: 3 additions & 2 deletions tools/depmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods, uint16_
n_r++;
}

stack = malloc(n_r * sizeof(void *));
_clang_suppress_alloc_ stack = malloc(n_r * sizeof(void *));
if (stack == NULL) {
ERR("No memory to report cycles\n");
goto out_list;
Expand Down Expand Up @@ -2920,7 +2920,8 @@ static int do_depmod(int argc, char *argv[])
break;
case 'C': {
size_t bytes = sizeof(char *) * (n_config_paths + 2);
void *tmp = realloc(config_paths, bytes);
_clang_suppress_alloc_ void *tmp = realloc(config_paths, bytes);

if (!tmp) {
fputs("Error: out-of-memory\n", stderr);
goto cmdline_failed;
Expand Down