]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
shared: mass convert with clang-format
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 11 Sep 2024 16:30:21 +0000 (17:30 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 24 Sep 2024 14:59:20 +0000 (09:59 -0500)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/118
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/array.c
shared/hash.c
shared/hash.h
shared/macro.h
shared/missing.h
shared/scratchbuf.h
shared/strbuf.c
shared/util.c
shared/util.h

index 299021fcb804e67d784998d8137b39eb3053c142..964ab2f29016bed7bb1fa0e06ae03064ba705516 100644 (file)
@@ -13,7 +13,6 @@
 
 /* basic pointer array growing in steps */
 
-
 static int array_realloc(struct array *array, size_t new_total)
 {
        void *tmp;
@@ -74,21 +73,22 @@ int array_append_unique(struct array *array, const void *element)
        return array_append(array, element);
 }
 
-void array_pop(struct array *array) {
+void array_pop(struct array *array)
+{
        if (array->count == 0)
                return;
        array->count--;
        array_trim(array);
 }
 
-void array_free_array(struct array *array) {
+void array_free_array(struct array *array)
+{
        free(array->array);
        array->array = NULL;
        array->count = 0;
        array->total = 0;
 }
 
-
 void array_sort(struct array *array, int (*cmp)(const void *a, const void *b))
 {
        qsort(array->array, array->count, sizeof(void *), cmp);
index 2c77ef49ba3e56133dd139166467b0c6b6c66404..df35f45388f86cbedc360e85fddfa22772896425 100644 (file)
@@ -30,14 +30,12 @@ struct hash {
        struct hash_bucket buckets[];
 };
 
-struct hash *hash_new(unsigned int n_buckets,
-                                       void (*free_value)(void *value))
+struct hash *hash_new(unsigned int n_buckets, void (*free_value)(void *value))
 {
        struct hash *hash;
 
        n_buckets = ALIGN_POWER2(n_buckets);
-       hash = calloc(1, sizeof(struct hash) +
-                     n_buckets * sizeof(struct hash_bucket));
+       hash = calloc(1, sizeof(struct hash) + n_buckets * sizeof(struct hash_bucket));
        if (hash == NULL)
                return NULL;
        hash->n_buckets = n_buckets;
@@ -84,7 +82,7 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len)
 
        /* Main loop */
        for (; len > 0; len--) {
-               hash += get_unaligned((uint16_t *) key);
+               hash += get_unaligned((uint16_t *)key);
                tmp = (get_unaligned((uint16_t *)(key + 2)) << 11) ^ hash;
                hash = (hash << 16) ^ tmp;
                key += 4;
@@ -94,14 +92,14 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len)
        /* Handle end cases */
        switch (rem) {
        case 3:
-               hash += get_unaligned((uint16_t *) key);
+               hash += get_unaligned((uint16_t *)key);
                hash ^= hash << 16;
                hash ^= key[2] << 18;
                hash += hash >> 11;
                break;
 
        case 2:
-               hash += get_unaligned((uint16_t *) key);
+               hash += get_unaligned((uint16_t *)key);
                hash ^= hash << 11;
                hash += hash >> 17;
                break;
@@ -232,8 +230,8 @@ void *hash_find(const struct hash *hash, const char *key)
        if (!bucket->entries)
                return NULL;
 
-       entry = bsearch(&se, bucket->entries, bucket->used,
-                       sizeof(struct hash_entry), hash_entry_cmp);
+       entry = bsearch(&se, bucket->entries, bucket->used, sizeof(struct hash_entry),
+                       hash_entry_cmp);
 
        return entry ? (void *)entry->value : NULL;
 }
@@ -251,8 +249,8 @@ int hash_del(struct hash *hash, const char *key)
                .value = NULL,
        };
 
-       entry = bsearch(&se, bucket->entries, bucket->used,
-               sizeof(struct hash_entry), hash_entry_cmp);
+       entry = bsearch(&se, bucket->entries, bucket->used, sizeof(struct hash_entry),
+                       hash_entry_cmp);
        if (entry == NULL)
                return -ENOENT;
 
@@ -260,8 +258,7 @@ int hash_del(struct hash *hash, const char *key)
                hash->free_value((void *)entry->value);
 
        entry_end = bucket->entries + bucket->used;
-       memmove(entry, entry + 1,
-               (entry_end - entry) * sizeof(struct hash_entry));
+       memmove(entry, entry + 1, (entry_end - entry) * sizeof(struct hash_entry));
 
        bucket->used--;
        hash->count--;
@@ -269,8 +266,7 @@ int hash_del(struct hash *hash, const char *key)
        steps_used = bucket->used / hash->step;
        steps_total = bucket->total / hash->step;
        if (steps_used + 1 < steps_total) {
-               size_t size = (steps_used + 1) *
-                       hash->step * sizeof(struct hash_entry);
+               size_t size = (steps_used + 1) * hash->step * sizeof(struct hash_entry);
                struct hash_entry *tmp = realloc(bucket->entries, size);
                if (tmp) {
                        bucket->entries = tmp;
@@ -293,8 +289,7 @@ void hash_iter_init(const struct hash *hash, struct hash_iter *iter)
        iter->entry = -1;
 }
 
-bool hash_iter_next(struct hash_iter *iter, const char **key,
-                                                       const void **value)
+bool hash_iter_next(struct hash_iter *iter, const char **key, const void **value)
 {
        const struct hash_bucket *b = iter->hash->buckets + iter->bucket;
        const struct hash_entry *e;
@@ -305,7 +300,7 @@ bool hash_iter_next(struct hash_iter *iter, const char **key,
                iter->entry = 0;
 
                for (iter->bucket++; iter->bucket < iter->hash->n_buckets;
-                                                       iter->bucket++) {
+                    iter->bucket++) {
                        b = iter->hash->buckets + iter->bucket;
 
                        if (b->used > 0)
index ca0af05724851c21fc61aa9143dd84da3af4b050..96dfa5d1910a0c7a19784778e7450224299c43ae 100644 (file)
@@ -18,5 +18,4 @@ int hash_del(struct hash *hash, const char *key);
 void *hash_find(const struct hash *hash, const char *key);
 unsigned int hash_get_count(const struct hash *hash);
 void hash_iter_init(const struct hash *hash, struct hash_iter *iter);
-bool hash_iter_next(struct hash_iter *iter, const char **key,
-                                                       const void **value);
+bool hash_iter_next(struct hash_iter *iter, const char **key, const void **value);
index 5d08a63d0c5f1e14c743877f5c402b1d6f7560ce..b7e91c74ef2c6351b1a5416e4390ed05a7d619db 100644 (file)
@@ -7,27 +7,26 @@
 #include <stddef.h>
 
 #if defined(HAVE_STATIC_ASSERT)
-#define assert_cc(expr) \
-       _Static_assert((expr), #expr)
+#define assert_cc(expr) _Static_assert((expr), #expr)
 #else
-#define assert_cc(expr) \
-       do { (void) sizeof(char [1 - 2*!(expr)]); } while(0)
+#define assert_cc(expr)                              \
+       do {                                         \
+               (void)sizeof(char[1 - 2 * !(expr)]); \
+       } while (0)
 #endif
 
-#define check_types_match(expr1, expr2)                \
-       ((typeof(expr1) *)0 != (typeof(expr2) *)0)
-
-#define container_of(member_ptr, containing_type, member)              \
-       ((containing_type *)                                            \
-        ((char *)(member_ptr) - offsetof(containing_type, member))     \
-        - check_types_match(*(member_ptr), ((containing_type *)0)->member))
+#define check_types_match(expr1, expr2) ((typeof(expr1) *)0 != (typeof(expr2) *)0)
 
+#define container_of(member_ptr, containing_type, member)                                \
+       ((containing_type *)((char *)(member_ptr) - offsetof(containing_type, member)) - \
+        check_types_match(*(member_ptr), ((containing_type *)0)->member))
 
 /* Two gcc extensions.
  * &a[0] degrades to a pointer: a different type from an array */
-#define _array_size_chk(arr) ({ \
-       assert_cc(!__builtin_types_compatible_p(typeof(arr), typeof(&(arr)[0]))); \
-       0; \
+#define _array_size_chk(arr)                                                              \
+       ({                                                                                \
+               assert_cc(!__builtin_types_compatible_p(typeof(arr), typeof(&(arr)[0]))); \
+               0;                                                                        \
        })
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))
 #define XSTRINGIFY(x) #x
 #define STRINGIFY(x) XSTRINGIFY(x)
 
-#define XCONCATENATE(x, y) x ## y
+#define XCONCATENATE(x, y) x##y
 #define CONCATENATE(x, y) XCONCATENATE(x, y)
 #define UNIQ(x) CONCATENATE(x, __COUNTER__)
 
 /* Attributes */
 
 #define _must_check_ __attribute__((warn_unused_result))
-#define _printf_format_(a,b) __attribute__((format (printf, a, b)))
+#define _printf_format_(a, b) __attribute__((format(printf, a, b)))
 #define _unused_ __attribute__((unused))
 #define _always_inline_ __inline__ __attribute__((always_inline))
 #define _cleanup_(x) __attribute__((cleanup(x)))
-#define _nonnull_(...) __attribute__((nonnull (__VA_ARGS__)))
+#define _nonnull_(...) __attribute__((nonnull(__VA_ARGS__)))
 #define _nonnull_all_ __attribute__((nonnull))
 
 /* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
index 9dbbd70737f4190edfe352b652561ec542959000..1f44f89ed528d928909f74879bf3782a5d1ab45f 100644 (file)
@@ -16,8 +16,8 @@
 #define MODULE_INIT_COMPRESSED_FILE 4
 
 #ifndef __NR_finit_module
-# warning __NR_finit_module missing - kmod might not work correctly
-# define __NR_finit_module -1
+#warning __NR_finit_module missing - kmod might not work correctly
+#define __NR_finit_module -1
 #endif
 
 #ifndef HAVE_FINIT_MODULE
index 27ea9d9f6008e4ce6ec6098b5d49f3267c02b0ae..7ba843731e95deeee7788db966696304acf593e6 100644 (file)
@@ -24,8 +24,9 @@ static inline char *scratchbuf_str(struct scratchbuf *buf)
        return buf->bytes;
 }
 
-#define SCRATCHBUF_INITIALIZER(buf_) {                 \
-       .bytes = buf_,                                  \
-       .size = sizeof(buf_) + _array_size_chk(buf_),   \
-       .need_free = false,                             \
-}
+#define SCRATCHBUF_INITIALIZER(buf_)                          \
+       {                                                     \
+               .bytes = buf_,                                \
+               .size = sizeof(buf_) + _array_size_chk(buf_), \
+               .need_free = false,                           \
+       }
index b032f40f67069412c7929df441e1d339eb943200..f89a97d70de76f3ea173bdb909e6e757e57d33b5 100644 (file)
@@ -111,4 +111,3 @@ void strbuf_clear(struct strbuf *buf)
 {
        buf->used = 0;
 }
-
index f83bc353c49e598bac5663f66625c0f23ca2b9ff..b9da7c4e9a03c0fe27c2b6c42922ba75591d54d6 100644 (file)
 #include <shared/missing.h>
 #include <shared/util.h>
 
-#define USEC_PER_SEC  1000000ULL
+#define USEC_PER_SEC 1000000ULL
 #define NSEC_PER_USEC 1000ULL
 
 static const struct kmod_ext {
        const char *ext;
        size_t len;
 } kmod_exts[] = {
-       {KMOD_EXTENSION_UNCOMPRESSED, sizeof(KMOD_EXTENSION_UNCOMPRESSED) - 1},
+       { KMOD_EXTENSION_UNCOMPRESSED, sizeof(KMOD_EXTENSION_UNCOMPRESSED) - 1 },
 #ifdef ENABLE_ZLIB
-       {".ko.gz", sizeof(".ko.gz") - 1},
+       { ".ko.gz", sizeof(".ko.gz") - 1 },
 #endif
 #ifdef ENABLE_XZ
-       {".ko.xz", sizeof(".ko.xz") - 1},
+       { ".ko.xz", sizeof(".ko.xz") - 1 },
 #endif
 #ifdef ENABLE_ZSTD
-       {".ko.zst", sizeof(".ko.zst") - 1},
+       { ".ko.zst", sizeof(".ko.zst") - 1 },
 #endif
-       { },
+       {},
 };
 
 /* string handling functions and memory allocations                         */
@@ -292,10 +292,10 @@ char *freadline_wrapped(FILE *fp, unsigned int *linenum)
        if (buf == NULL)
                return NULL;
 
-       for(;;) {
+       for (;;) {
                int ch = getc_unlocked(fp);
 
-               switch(ch) {
+               switch (ch) {
                case EOF:
                        if (i == 0)
                                return NULL;
@@ -453,14 +453,14 @@ int mkdir_parents(const char *path, mode_t mode)
 
 static unsigned long long ts_usec(const struct timespec *ts)
 {
-       return (unsigned long long) ts->tv_sec * USEC_PER_SEC +
-              (unsigned long long) ts->tv_nsec / NSEC_PER_USEC;
+       return (unsigned long long)ts->tv_sec * USEC_PER_SEC +
+              (unsigned long long)ts->tv_nsec / NSEC_PER_USEC;
 }
 
 static unsigned long long ts_msec(const struct timespec *ts)
 {
-       return (unsigned long long) ts->tv_sec * MSEC_PER_SEC +
-              (unsigned long long) ts->tv_nsec / NSEC_PER_MSEC;
+       return (unsigned long long)ts->tv_sec * MSEC_PER_SEC +
+              (unsigned long long)ts->tv_nsec / NSEC_PER_MSEC;
 }
 
 static struct timespec msec_ts(unsigned long long msec)
@@ -487,8 +487,7 @@ int sleep_until_msec(unsigned long long msec)
 /*
  * Exponential retry backoff with tail
  */
-unsigned long long get_backoff_delta_msec(unsigned long long t0,
-                                         unsigned long long tend,
+unsigned long long get_backoff_delta_msec(unsigned long long t0, unsigned long long tend,
                                          unsigned long long *delta)
 {
        unsigned long long t;
@@ -534,6 +533,6 @@ unsigned long long stat_mstamp(const struct stat *st)
 #ifdef HAVE_STRUCT_STAT_ST_MTIM
        return ts_usec(&st->st_mtim);
 #else
-       return (unsigned long long) st->st_mtime;
+       return (unsigned long long)st->st_mtime;
 #endif
 }
index 1b87be0b75e41e9909f0c09410e09f6cdf269568..bcd834e5b371f98aa0ba1b188a3186375ac92171 100644 (file)
@@ -24,10 +24,13 @@ _nonnull_all_ void *memdup(const void *p, size_t n);
 /* ************************************************************************ */
 #define KMOD_EXTENSION_UNCOMPRESSED ".ko"
 
-_must_check_ _nonnull_(1, 2) int alias_normalize(const char *alias, char buf[static PATH_MAX], size_t *len);
+_must_check_ _nonnull_(1, 2) int alias_normalize(const char *alias,
+                                                char buf[static PATH_MAX], size_t *len);
 _must_check_ int underscores(char *s);
-_nonnull_(1, 2) char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t *len);
-_nonnull_(2) char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len);
+_nonnull_(1, 2) char *modname_normalize(const char *modname, char buf[static PATH_MAX],
+                                       size_t *len);
+_nonnull_(2) char *path_to_modname(const char *path, char buf[static PATH_MAX],
+                                  size_t *len);
 _nonnull_all_ bool path_ends_with_kmod_ext(const char *path, size_t len);
 
 /* read-like and fread-like functions                                       */
@@ -47,36 +50,34 @@ unsigned long long stat_mstamp(const struct stat *st);
 
 /* time-related functions
  * ************************************************************************ */
-#define USEC_PER_SEC   1000000ULL
-#define USEC_PER_MSEC  1000ULL
-#define MSEC_PER_SEC   1000ULL
-#define NSEC_PER_MSEC  1000000ULL
+#define USEC_PER_SEC 1000000ULL
+#define USEC_PER_MSEC 1000ULL
+#define MSEC_PER_SEC 1000ULL
+#define NSEC_PER_MSEC 1000000ULL
 
 unsigned long long now_usec(void);
 unsigned long long now_msec(void);
 int sleep_until_msec(unsigned long long msec);
-unsigned long long get_backoff_delta_msec(unsigned long long t0,
-                                         unsigned long long tend,
+unsigned long long get_backoff_delta_msec(unsigned long long t0, unsigned long long tend,
                                          unsigned long long *delta);
 
-
 /* endianness and alignments                                                */
 /* ************************************************************************ */
-#define get_unaligned(ptr)                     \
-({                                             \
-       struct __attribute__((packed)) {        \
-               typeof(*(ptr)) __v;             \
-       } *__p = (typeof(__p)) (ptr);           \
-       __p->__v;                               \
-})
+#define get_unaligned(ptr)                       \
+       ({                                       \
+               struct __attribute__((packed)) { \
+                       typeof(*(ptr)) __v;      \
+               } *__p = (typeof(__p))(ptr);     \
+               __p->__v;                        \
+       })
 
-#define put_unaligned(val, ptr)                        \
-do {                                           \
-       struct __attribute__((packed)) {        \
-               typeof(*(ptr)) __v;             \
-       } *__p = (typeof(__p)) (ptr);           \
-       __p->__v = (val);                       \
-} while(0)
+#define put_unaligned(val, ptr)                  \
+       do {                                     \
+               struct __attribute__((packed)) { \
+                       typeof(*(ptr)) __v;      \
+               } *__p = (typeof(__p))(ptr);     \
+               __p->__v = (val);                \
+       } while (0)
 
 static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)
 {
@@ -85,8 +86,9 @@ static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)
 
 /* misc                                                                     */
 /* ************************************************************************ */
-static inline void freep(void *p) {
-        free(*(void**) p);
+static inline void freep(void *p)
+{
+       free(*(void **)p);
 }
 #define _cleanup_free_ _cleanup_(freep)