]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gendwarfksyms: use preferred form of sizeof for allocation
authorGiuliano Procida <gprocida@google.com>
Tue, 1 Jul 2025 15:19:10 +0000 (16:19 +0100)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 26 Jul 2025 06:31:30 +0000 (15:31 +0900)
The preferred form is to use the variable being allocated to, rather
than explicitly supplying a type name which might become stale.

Also do this for memset.

Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Giuliano Procida <gprocida@google.com>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/gendwarfksyms/cache.c
scripts/gendwarfksyms/die.c
scripts/gendwarfksyms/dwarf.c
scripts/gendwarfksyms/kabi.c
scripts/gendwarfksyms/symbols.c
scripts/gendwarfksyms/types.c

index c9c19b86a686f8d2177997607ce52016462203c4..1c640db93db3fc94769d85f78a619107f026c122 100644 (file)
@@ -15,7 +15,7 @@ void cache_set(struct cache *cache, unsigned long key, int value)
 {
        struct cache_item *ci;
 
-       ci = xmalloc(sizeof(struct cache_item));
+       ci = xmalloc(sizeof(*ci));
        ci->key = key;
        ci->value = value;
        hash_add(cache->cache, &ci->hash, hash_32(key));
index 6183bbbe7b54f31fd0cfbc8f1776c061f8449131..052f7a3f975a5090d7021a00da2bf4561c5fdb84 100644 (file)
@@ -33,7 +33,7 @@ static struct die *create_die(Dwarf_Die *die, enum die_state state)
 {
        struct die *cd;
 
-       cd = xmalloc(sizeof(struct die));
+       cd = xmalloc(sizeof(*cd));
        init_die(cd);
        cd->addr = (uintptr_t)die->addr;
 
@@ -123,7 +123,7 @@ static struct die_fragment *append_item(struct die *cd)
 {
        struct die_fragment *df;
 
-       df = xmalloc(sizeof(struct die_fragment));
+       df = xmalloc(sizeof(*df));
        df->type = FRAGMENT_EMPTY;
        list_add_tail(&df->list, &cd->fragments);
        return df;
index 13ea7bf1ae7dcdd208d25fe54655f1c0fb041907..3538a7d9cb070b4a94fb77b888d8d4c5c8d98b60 100644 (file)
@@ -634,7 +634,7 @@ static int get_union_kabi_status(Dwarf_Die *die, Dwarf_Die *placeholder,
         * Note that the user of this feature is responsible for ensuring
         * that the structure actually remains ABI compatible.
         */
-       memset(&state.kabi, 0, sizeof(struct kabi_state));
+       memset(&state.kabi, 0, sizeof(state.kabi));
 
        res = checkp(process_die_container(&state, NULL, die,
                                           check_union_member_kabi_status,
index b3ade713778f1be725a70fd1209c7ccb4a387d0e..e3c2a3ccf51a070bc8f43b0b9fe517abc5f10d70 100644 (file)
@@ -228,7 +228,7 @@ void kabi_read_rules(int fd)
                if (type == KABI_RULE_TYPE_UNKNOWN)
                        error("unsupported kABI rule type: '%s'", field);
 
-               rule = xmalloc(sizeof(struct rule));
+               rule = xmalloc(sizeof(*rule));
 
                rule->type = type;
                rule->target = xstrdup(get_rule_field(&rule_str, &left));
index 327f87389c3433a506f6f08d4c383915ba3cba94..35ed594f0749b72ceea391e037a80fa923eea75c 100644 (file)
@@ -146,7 +146,7 @@ void symbol_read_exports(FILE *file)
                        continue;
                }
 
-               sym = xcalloc(1, sizeof(struct symbol));
+               sym = xcalloc(1, sizeof(*sym));
                sym->name = name;
                sym->addr.section = SHN_UNDEF;
                sym->state = SYMBOL_UNPROCESSED;
index 7bd459ea6c597cf1d37892e3e0e99d618dfa6ec2..5344c7b9a9cec3c0c9e3634bd5f77e4e86397589 100644 (file)
@@ -43,7 +43,7 @@ static int type_list_append(struct list_head *list, const char *s, void *owned)
        if (!s)
                return 0;
 
-       entry = xmalloc(sizeof(struct type_list_entry));
+       entry = xmalloc(sizeof(*entry));
        entry->str = s;
        entry->owned = owned;
        list_add_tail(&entry->list, list);
@@ -120,7 +120,7 @@ static struct type_expansion *type_map_add(const char *name,
        struct type_expansion *e;
 
        if (__type_map_get(name, &e)) {
-               e = xmalloc(sizeof(struct type_expansion));
+               e = xmalloc(sizeof(*e));
                type_expansion_init(e);
                e->name = xstrdup(name);