summaryrefslogtreecommitdiff
path: root/security/keys
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-21 10:49:23 +0300
committerKees Cook <kees@kernel.org>2026-02-21 12:02:28 +0300
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /security/keys
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.xz
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 'security/keys')
-rw-r--r--security/keys/key.c2
-rw-r--r--security/keys/keyctl.c4
-rw-r--r--security/keys/keyring.c2
-rw-r--r--security/keys/request_key_auth.c2
-rw-r--r--security/keys/trusted-keys/trusted_core.c2
-rw-r--r--security/keys/trusted-keys/trusted_pkwm.c4
-rw-r--r--security/keys/trusted-keys/trusted_tpm1.c7
7 files changed, 11 insertions, 12 deletions
diff --git a/security/keys/key.c b/security/keys/key.c
index 3bbdde778631..8ca0777f22d3 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -77,7 +77,7 @@ try_again:
spin_unlock(&key_user_lock);
user = NULL;
- candidate = kmalloc(sizeof(struct key_user), GFP_KERNEL);
+ candidate = kmalloc_obj(struct key_user, GFP_KERNEL);
if (unlikely(!candidate))
goto out;
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index ab927a142f51..7d8a0de7c7c4 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -1796,13 +1796,13 @@ long keyctl_watch_key(key_serial_t id, int watch_queue_fd, int watch_id)
if (watch_id >= 0) {
ret = -ENOMEM;
if (!key->watchers) {
- wlist = kzalloc(sizeof(*wlist), GFP_KERNEL);
+ wlist = kzalloc_obj(*wlist, GFP_KERNEL);
if (!wlist)
goto err_wqueue;
init_watch_list(wlist, NULL);
}
- watch = kzalloc(sizeof(*watch), GFP_KERNEL);
+ watch = kzalloc_obj(*watch, GFP_KERNEL);
if (!watch)
goto err_wlist;
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index f331725d5a37..9a1685035be5 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -977,7 +977,7 @@ static struct key_restriction *keyring_restriction_alloc(
key_restrict_link_func_t check)
{
struct key_restriction *keyres =
- kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
+ kzalloc_obj(struct key_restriction, GFP_KERNEL);
if (!keyres)
return ERR_PTR(-ENOMEM);
diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c
index 8f33cd170e42..f0de3e9d9743 100644
--- a/security/keys/request_key_auth.c
+++ b/security/keys/request_key_auth.c
@@ -171,7 +171,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
kenter("%d,", target->serial);
/* allocate a auth record */
- rka = kzalloc(sizeof(*rka), GFP_KERNEL);
+ rka = kzalloc_obj(*rka, GFP_KERNEL);
if (!rka)
goto error;
rka->callout_info = kmemdup(callout_info, callout_len, GFP_KERNEL);
diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index 9046123d94de..fb9ff3d18292 100644
--- a/security/keys/trusted-keys/trusted_core.c
+++ b/security/keys/trusted-keys/trusted_core.c
@@ -134,7 +134,7 @@ static struct trusted_key_payload *trusted_payload_alloc(struct key *key)
ret = key_payload_reserve(key, sizeof(*p));
if (ret < 0)
goto err;
- p = kzalloc(sizeof(*p), GFP_KERNEL);
+ p = kzalloc_obj(*p, GFP_KERNEL);
if (!p)
goto err;
diff --git a/security/keys/trusted-keys/trusted_pkwm.c b/security/keys/trusted-keys/trusted_pkwm.c
index 4f391b77a907..aab8fbc49280 100644
--- a/security/keys/trusted-keys/trusted_pkwm.c
+++ b/security/keys/trusted-keys/trusted_pkwm.c
@@ -62,10 +62,10 @@ static struct trusted_key_options *trusted_options_alloc(void)
struct trusted_key_options *options;
struct trusted_pkwm_options *pkwm;
- options = kzalloc(sizeof(*options), GFP_KERNEL);
+ options = kzalloc_obj(*options, GFP_KERNEL);
if (options) {
- pkwm = kzalloc(sizeof(*pkwm), GFP_KERNEL);
+ pkwm = kzalloc_obj(*pkwm, GFP_KERNEL);
if (!pkwm) {
kfree_sensitive(options);
diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
index c865c97aa1b4..ce9b26dd846e 100644
--- a/security/keys/trusted-keys/trusted_tpm1.c
+++ b/security/keys/trusted-keys/trusted_tpm1.c
@@ -440,7 +440,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
int i;
/* alloc some work space for all the hashes */
- td = kmalloc(sizeof *td, GFP_KERNEL);
+ td = kmalloc_obj(*td, GFP_KERNEL);
if (!td)
return -ENOMEM;
@@ -838,7 +838,7 @@ static struct trusted_key_options *trusted_options_alloc(void)
if (tpm2 < 0)
return NULL;
- options = kzalloc(sizeof *options, GFP_KERNEL);
+ options = kzalloc_obj(*options, GFP_KERNEL);
if (options) {
/* set any non-zero defaults */
options->keytype = SRK_keytype;
@@ -946,8 +946,7 @@ static int __init init_digests(void)
{
int i;
- digests = kcalloc(chip->nr_allocated_banks, sizeof(*digests),
- GFP_KERNEL);
+ digests = kzalloc_objs(*digests, chip->nr_allocated_banks, GFP_KERNEL);
if (!digests)
return -ENOMEM;