diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /net/netlabel | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'net/netlabel')
| -rw-r--r-- | net/netlabel/netlabel_calipso.c | 2 | ||||
| -rw-r--r-- | net/netlabel/netlabel_cipso_v4.c | 8 | ||||
| -rw-r--r-- | net/netlabel/netlabel_domainhash.c | 8 | ||||
| -rw-r--r-- | net/netlabel/netlabel_kapi.c | 20 | ||||
| -rw-r--r-- | net/netlabel/netlabel_mgmt.c | 10 | ||||
| -rw-r--r-- | net/netlabel/netlabel_unlabeled.c | 14 |
6 files changed, 29 insertions, 33 deletions
diff --git a/net/netlabel/netlabel_calipso.c b/net/netlabel/netlabel_calipso.c index a07c2216d28b..fae0bee5c065 100644 --- a/net/netlabel/netlabel_calipso.c +++ b/net/netlabel/netlabel_calipso.c @@ -95,7 +95,7 @@ static int netlbl_calipso_add_pass(struct genl_info *info, int ret_val; struct calipso_doi *doi_def = NULL; - doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); + doi_def = kmalloc_obj(*doi_def, GFP_KERNEL); if (!doi_def) return -ENOMEM; doi_def->type = CALIPSO_MAP_PASS; diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index fa08ee75ac06..526f3dc3e67a 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c @@ -139,10 +139,10 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, NULL) != 0) return -EINVAL; - doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); + doi_def = kmalloc_obj(*doi_def, GFP_KERNEL); if (doi_def == NULL) return -ENOMEM; - doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL); + doi_def->map.std = kzalloc_obj(*doi_def->map.std, GFP_KERNEL); if (doi_def->map.std == NULL) { kfree(doi_def); return -ENOMEM; @@ -332,7 +332,7 @@ static int netlbl_cipsov4_add_pass(struct genl_info *info, if (!info->attrs[NLBL_CIPSOV4_A_TAGLST]) return -EINVAL; - doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); + doi_def = kmalloc_obj(*doi_def, GFP_KERNEL); if (doi_def == NULL) return -ENOMEM; doi_def->type = CIPSO_V4_MAP_PASS; @@ -371,7 +371,7 @@ static int netlbl_cipsov4_add_local(struct genl_info *info, if (!info->attrs[NLBL_CIPSOV4_A_TAGLST]) return -EINVAL; - doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); + doi_def = kmalloc_obj(*doi_def, GFP_KERNEL); if (doi_def == NULL) return -ENOMEM; doi_def->type = CIPSO_V4_MAP_LOCAL; diff --git a/net/netlabel/netlabel_domainhash.c b/net/netlabel/netlabel_domainhash.c index 8158a25972b4..fc014849d6b3 100644 --- a/net/netlabel/netlabel_domainhash.c +++ b/net/netlabel/netlabel_domainhash.c @@ -367,13 +367,11 @@ int __init netlbl_domhsh_init(u32 size) if (size == 0) return -EINVAL; - hsh_tbl = kmalloc(sizeof(*hsh_tbl), GFP_KERNEL); + hsh_tbl = kmalloc_obj(*hsh_tbl, GFP_KERNEL); if (hsh_tbl == NULL) return -ENOMEM; hsh_tbl->size = 1 << size; - hsh_tbl->tbl = kcalloc(hsh_tbl->size, - sizeof(struct list_head), - GFP_KERNEL); + hsh_tbl->tbl = kzalloc_objs(struct list_head, hsh_tbl->size, GFP_KERNEL); if (hsh_tbl->tbl == NULL) { kfree(hsh_tbl); return -ENOMEM; @@ -453,7 +451,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry, ret_val = -EINVAL; goto add_return; } - entry_b = kzalloc(sizeof(*entry_b), GFP_ATOMIC); + entry_b = kzalloc_obj(*entry_b, GFP_ATOMIC); if (entry_b == NULL) { ret_val = -ENOMEM; goto add_return; diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index 33b77084a4e5..3583fa63dd01 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c @@ -104,7 +104,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain, struct netlbl_domaddr4_map *map4 = NULL; struct netlbl_domaddr6_map *map6 = NULL; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (entry == NULL) return -ENOMEM; if (domain != NULL) { @@ -117,7 +117,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain, if (addr == NULL && mask == NULL) entry->def.type = NETLBL_NLTYPE_UNLABELED; else if (addr != NULL && mask != NULL) { - addrmap = kzalloc(sizeof(*addrmap), GFP_ATOMIC); + addrmap = kzalloc_obj(*addrmap, GFP_ATOMIC); if (addrmap == NULL) goto cfg_unlbl_map_add_failure; INIT_LIST_HEAD(&addrmap->list4); @@ -127,7 +127,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain, case AF_INET: { const struct in_addr *addr4 = addr; const struct in_addr *mask4 = mask; - map4 = kzalloc(sizeof(*map4), GFP_ATOMIC); + map4 = kzalloc_obj(*map4, GFP_ATOMIC); if (map4 == NULL) goto cfg_unlbl_map_add_failure; map4->def.type = NETLBL_NLTYPE_UNLABELED; @@ -144,7 +144,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain, case AF_INET6: { const struct in6_addr *addr6 = addr; const struct in6_addr *mask6 = mask; - map6 = kzalloc(sizeof(*map6), GFP_ATOMIC); + map6 = kzalloc_obj(*map6, GFP_ATOMIC); if (map6 == NULL) goto cfg_unlbl_map_add_failure; map6->def.type = NETLBL_NLTYPE_UNLABELED; @@ -336,7 +336,7 @@ int netlbl_cfg_cipsov4_map_add(u32 doi, if (doi_def == NULL) return -ENOENT; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (entry == NULL) goto out_entry; entry->family = AF_INET; @@ -350,13 +350,13 @@ int netlbl_cfg_cipsov4_map_add(u32 doi, entry->def.cipso = doi_def; entry->def.type = NETLBL_NLTYPE_CIPSOV4; } else if (addr != NULL && mask != NULL) { - addrmap = kzalloc(sizeof(*addrmap), GFP_ATOMIC); + addrmap = kzalloc_obj(*addrmap, GFP_ATOMIC); if (addrmap == NULL) goto out_addrmap; INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); - addrinfo = kzalloc(sizeof(*addrinfo), GFP_ATOMIC); + addrinfo = kzalloc_obj(*addrinfo, GFP_ATOMIC); if (addrinfo == NULL) goto out_addrinfo; addrinfo->def.cipso = doi_def; @@ -462,7 +462,7 @@ int netlbl_cfg_calipso_map_add(u32 doi, if (doi_def == NULL) return -ENOENT; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (entry == NULL) goto out_entry; entry->family = AF_INET6; @@ -476,13 +476,13 @@ int netlbl_cfg_calipso_map_add(u32 doi, entry->def.calipso = doi_def; entry->def.type = NETLBL_NLTYPE_CALIPSO; } else if (addr != NULL && mask != NULL) { - addrmap = kzalloc(sizeof(*addrmap), GFP_ATOMIC); + addrmap = kzalloc_obj(*addrmap, GFP_ATOMIC); if (addrmap == NULL) goto out_addrmap; INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); - addrinfo = kzalloc(sizeof(*addrinfo), GFP_ATOMIC); + addrinfo = kzalloc_obj(*addrinfo, GFP_ATOMIC); if (addrinfo == NULL) goto out_addrinfo; addrinfo->def.calipso = doi_def; diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index 079fe72a6384..13f45fbff824 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -84,7 +84,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, struct calipso_doi *calipso = NULL; #endif u32 tmp_val; - struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL); + struct netlbl_dom_map *entry = kzalloc_obj(*entry, GFP_KERNEL); if (!entry) return -ENOMEM; @@ -148,7 +148,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, struct in_addr *mask; struct netlbl_domaddr4_map *map; - addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); + addrmap = kzalloc_obj(*addrmap, GFP_KERNEL); if (addrmap == NULL) { ret_val = -ENOMEM; goto add_doi_put_def; @@ -169,7 +169,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]); - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (map == NULL) { ret_val = -ENOMEM; goto add_free_addrmap; @@ -195,7 +195,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, struct in6_addr *mask; struct netlbl_domaddr6_map *map; - addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); + addrmap = kzalloc_obj(*addrmap, GFP_KERNEL); if (addrmap == NULL) { ret_val = -ENOMEM; goto add_doi_put_def; @@ -216,7 +216,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]); - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (map == NULL) { ret_val = -ENOMEM; goto add_free_addrmap; diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index dfda9ea61971..ab68324c08d9 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -236,7 +236,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, int ret_val; struct netlbl_unlhsh_addr4 *entry; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (entry == NULL) return -ENOMEM; @@ -276,7 +276,7 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, int ret_val; struct netlbl_unlhsh_addr6 *entry; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (entry == NULL) return -ENOMEM; @@ -314,7 +314,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex) u32 bkt; struct netlbl_unlhsh_iface *iface; - iface = kzalloc(sizeof(*iface), GFP_ATOMIC); + iface = kzalloc_obj(*iface, GFP_ATOMIC); if (iface == NULL) return NULL; @@ -1413,13 +1413,11 @@ int __init netlbl_unlabel_init(u32 size) if (size == 0) return -EINVAL; - hsh_tbl = kmalloc(sizeof(*hsh_tbl), GFP_KERNEL); + hsh_tbl = kmalloc_obj(*hsh_tbl, GFP_KERNEL); if (hsh_tbl == NULL) return -ENOMEM; hsh_tbl->size = 1 << size; - hsh_tbl->tbl = kcalloc(hsh_tbl->size, - sizeof(struct list_head), - GFP_KERNEL); + hsh_tbl->tbl = kzalloc_objs(struct list_head, hsh_tbl->size, GFP_KERNEL); if (hsh_tbl->tbl == NULL) { kfree(hsh_tbl); return -ENOMEM; @@ -1534,7 +1532,7 @@ int __init netlbl_unlabel_defconf(void) audit_info.loginuid = GLOBAL_ROOT_UID; audit_info.sessionid = 0; - entry = kzalloc(sizeof(*entry), GFP_KERNEL); + entry = kzalloc_obj(*entry, GFP_KERNEL); if (entry == NULL) return -ENOMEM; entry->family = AF_UNSPEC; |
