diff --git a/configure.ac b/configure.ac index 233fd274..c605c112 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index 165ba4dc..dfb1c083 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -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; diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 47c6305a..cdf90135 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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; diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index cd6c8948..7262abef 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -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, diff --git a/meson.build b/meson.build index b4789df4..c1088598 100644 --- a/meson.build +++ b/meson.build @@ -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', diff --git a/shared/macro.h b/shared/macro.h index 62876b05..2def79f2 100644 --- a/shared/macro.h +++ b/shared/macro.h @@ -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 and even on older gcc * compiler versions */ #ifndef noreturn diff --git a/shared/util.c b/shared/util.c index 6d1cf420..7a1f3ee8 100644 --- a/shared/util.c +++ b/shared/util.c @@ -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; diff --git a/shared/util.h b/shared/util.h index a9ce00a3..65d90dba 100644 --- a/shared/util.h +++ b/shared/util.h @@ -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) { diff --git a/tools/depmod.c b/tools/depmod.c index a1ba388d..3bb5a519 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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; @@ -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;