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 /fs/afs | |
| 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 'fs/afs')
| -rw-r--r-- | fs/afs/addr_list.c | 2 | ||||
| -rw-r--r-- | fs/afs/addr_prefs.c | 2 | ||||
| -rw-r--r-- | fs/afs/cell.c | 2 | ||||
| -rw-r--r-- | fs/afs/cmservice.c | 14 | ||||
| -rw-r--r-- | fs/afs/dir.c | 9 | ||||
| -rw-r--r-- | fs/afs/dir_silly.c | 2 | ||||
| -rw-r--r-- | fs/afs/file.c | 4 | ||||
| -rw-r--r-- | fs/afs/fs_operation.c | 2 | ||||
| -rw-r--r-- | fs/afs/fs_probe.c | 2 | ||||
| -rw-r--r-- | fs/afs/fsclient.c | 2 | ||||
| -rw-r--r-- | fs/afs/main.c | 2 | ||||
| -rw-r--r-- | fs/afs/proc.c | 2 | ||||
| -rw-r--r-- | fs/afs/rotate.c | 5 | ||||
| -rw-r--r-- | fs/afs/rxrpc.c | 2 | ||||
| -rw-r--r-- | fs/afs/security.c | 2 | ||||
| -rw-r--r-- | fs/afs/server.c | 2 | ||||
| -rw-r--r-- | fs/afs/server_list.c | 2 | ||||
| -rw-r--r-- | fs/afs/super.c | 4 | ||||
| -rw-r--r-- | fs/afs/vl_list.c | 5 | ||||
| -rw-r--r-- | fs/afs/vlclient.c | 2 | ||||
| -rw-r--r-- | fs/afs/volume.c | 2 | ||||
| -rw-r--r-- | fs/afs/xattr.c | 4 | ||||
| -rw-r--r-- | fs/afs/yfsclient.c | 4 |
23 files changed, 38 insertions, 41 deletions
diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index e941da5b6dd9..26590bfeae91 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -66,7 +66,7 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr) if (nr > AFS_MAX_ADDRESSES) nr = AFS_MAX_ADDRESSES; - alist = kzalloc(struct_size(alist, addrs, nr), GFP_KERNEL); + alist = kzalloc_flex(*alist, addrs, nr, GFP_KERNEL); if (!alist) return NULL; diff --git a/fs/afs/addr_prefs.c b/fs/afs/addr_prefs.c index 133736412c3d..f5a4fb6f609a 100644 --- a/fs/afs/addr_prefs.c +++ b/fs/afs/addr_prefs.c @@ -401,7 +401,7 @@ int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size) max_prefs = min_t(size_t, (psize - sizeof(*old)) / sizeof(old->prefs[0]), 255); ret = -ENOMEM; - preflist = kmalloc(struct_size(preflist, prefs, max_prefs), GFP_KERNEL); + preflist = kmalloc_flex(*preflist, prefs, max_prefs, GFP_KERNEL); if (!preflist) goto done; diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 71c10a05cebe..4331bf8e1dbd 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -134,7 +134,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, _enter("%*.*s,%s", namelen, namelen, name, addresses); - cell = kzalloc(sizeof(struct afs_cell), GFP_KERNEL); + cell = kzalloc_obj(struct afs_cell, GFP_KERNEL); if (!cell) { _leave(" = -ENOMEM"); return ERR_PTR(-ENOMEM); diff --git a/fs/afs/cmservice.c b/fs/afs/cmservice.c index 1a906805a9e3..a32e7c2864d2 100644 --- a/fs/afs/cmservice.c +++ b/fs/afs/cmservice.c @@ -228,9 +228,8 @@ static int afs_deliver_cb_callback(struct afs_call *call) return ret; _debug("unmarshall FID array"); - call->request = kcalloc(call->count, - sizeof(struct afs_callback_break), - GFP_KERNEL); + call->request = kzalloc_objs(struct afs_callback_break, + call->count, GFP_KERNEL); if (!call->request) return -ENOMEM; @@ -340,7 +339,7 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call) } _debug("unmarshall UUID"); - call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); + call->request = kmalloc_obj(struct afs_uuid, GFP_KERNEL); if (!call->request) return -ENOMEM; @@ -457,7 +456,7 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call) } _debug("unmarshall UUID"); - call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); + call->request = kmalloc_obj(struct afs_uuid, GFP_KERNEL); if (!call->request) return -ENOMEM; @@ -589,9 +588,8 @@ static int afs_deliver_yfs_cb_callback(struct afs_call *call) return ret; _debug("unmarshall FID array"); - call->request = kcalloc(call->count, - sizeof(struct afs_callback_break), - GFP_KERNEL); + call->request = kzalloc_objs(struct afs_callback_break, + call->count, GFP_KERNEL); if (!call->request) return -ENOMEM; diff --git a/fs/afs/dir.c b/fs/afs/dir.c index f4e9e12373ac..6f7380f25365 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -785,7 +785,7 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry) _enter("{%lu},%p{%pd},", dir->i_ino, dentry, dentry); - cookie = kzalloc(sizeof(struct afs_lookup_cookie), GFP_KERNEL); + cookie = kzalloc_obj(struct afs_lookup_cookie, GFP_KERNEL); if (!cookie) return ERR_PTR(-ENOMEM); @@ -834,9 +834,8 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry) /* Need space for examining all the selected files */ if (op->nr_files > 2) { - op->more_files = kvcalloc(op->nr_files - 2, - sizeof(struct afs_vnode_param), - GFP_KERNEL); + op->more_files = kvzalloc_objs(struct afs_vnode_param, + op->nr_files - 2, GFP_KERNEL); if (!op->more_files) { afs_op_nomem(op); goto out_op; @@ -2095,7 +2094,7 @@ static int afs_rename(struct mnt_idmap *idmap, struct inode *old_dir, goto error; ret = -ENOMEM; - op->more_files = kvcalloc(2, sizeof(struct afs_vnode_param), GFP_KERNEL); + op->more_files = kvzalloc_objs(struct afs_vnode_param, 2, GFP_KERNEL); if (!op->more_files) goto error; diff --git a/fs/afs/dir_silly.c b/fs/afs/dir_silly.c index 014495d4b868..f77bed45e808 100644 --- a/fs/afs/dir_silly.c +++ b/fs/afs/dir_silly.c @@ -69,7 +69,7 @@ static int afs_do_silly_rename(struct afs_vnode *dvnode, struct afs_vnode *vnode if (IS_ERR(op)) return PTR_ERR(op); - op->more_files = kvcalloc(2, sizeof(struct afs_vnode_param), GFP_KERNEL); + op->more_files = kvzalloc_objs(struct afs_vnode_param, 2, GFP_KERNEL); if (!op->more_files) { afs_put_operation(op); return -ENOMEM; diff --git a/fs/afs/file.c b/fs/afs/file.c index f66a92294284..5c429a746d76 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -86,7 +86,7 @@ int afs_cache_wb_key(struct afs_vnode *vnode, struct afs_file *af) { struct afs_wb_key *wbk, *p; - wbk = kzalloc(sizeof(struct afs_wb_key), GFP_KERNEL); + wbk = kzalloc_obj(struct afs_wb_key, GFP_KERNEL); if (!wbk) return -ENOMEM; refcount_set(&wbk->usage, 2); @@ -130,7 +130,7 @@ int afs_open(struct inode *inode, struct file *file) goto error; } - af = kzalloc(sizeof(*af), GFP_KERNEL); + af = kzalloc_obj(*af, GFP_KERNEL); if (!af) { ret = -ENOMEM; goto error_key; diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 8418813ee043..0ffd19f5279d 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -21,7 +21,7 @@ struct afs_operation *afs_alloc_operation(struct key *key, struct afs_volume *vo _enter(""); - op = kzalloc(sizeof(*op), GFP_KERNEL); + op = kzalloc_obj(*op, GFP_KERNEL); if (!op) return ERR_PTR(-ENOMEM); diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index e0030ac74ea0..0100ce4c62a0 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -244,7 +244,7 @@ int afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server, _enter("%pU", &server->uuid); - estate = kzalloc(sizeof(*estate), GFP_KERNEL); + estate = kzalloc_obj(*estate, GFP_KERNEL); if (!estate) return -ENOMEM; diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index bc9556991d7c..eb3520b9a282 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -2010,7 +2010,7 @@ static int afs_deliver_fs_fetch_acl(struct afs_call *call) size = call->count2 = ntohl(call->tmp); size = round_up(size, 4); - acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); + acl = kmalloc_flex(*acl, data, size, GFP_KERNEL); if (!acl) return -ENOMEM; op->acl = acl; diff --git a/fs/afs/main.c b/fs/afs/main.c index e6bb8237db98..7e09bf7aa03b 100644 --- a/fs/afs/main.c +++ b/fs/afs/main.c @@ -93,7 +93,7 @@ static int __net_init afs_net_init(struct net *net_ns) atomic_set(&net->servers_outstanding, 1); ret = -ENOMEM; - sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL); + sysnames = kzalloc_obj(*sysnames, GFP_KERNEL); if (!sysnames) goto error_sysnames; sysnames->subs[0] = (char *)&afs_init_sysname; diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 44520549b509..52e8195ef2b8 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -572,7 +572,7 @@ static int afs_proc_sysname_write(struct file *file, char *buf, size_t size) char *s, *p, *sub; int ret, len; - sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL); + sysnames = kzalloc_obj(*sysnames, GFP_KERNEL); if (!sysnames) return -ENOMEM; refcount_set(&sysnames->usage, 1); diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 6a4e7da10fc4..69e80c5b6610 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -46,8 +46,9 @@ static bool afs_start_fs_iteration(struct afs_operation *op, lockdep_is_held(&op->volume->servers_lock))); read_unlock(&op->volume->servers_lock); - op->server_states = kcalloc(op->server_list->nr_servers, sizeof(op->server_states[0]), - GFP_KERNEL); + op->server_states = kzalloc_objs(op->server_states[0], + op->server_list->nr_servers, + GFP_KERNEL); if (!op->server_states) { afs_op_nomem(op); trace_afs_rotate(op, afs_rotate_trace_nomem, 0); diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index bf0e4ea0aafd..588f8de51167 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -160,7 +160,7 @@ static struct afs_call *afs_alloc_call(struct afs_net *net, struct afs_call *call; int o; - call = kzalloc(sizeof(*call), gfp); + call = kzalloc_obj(*call, gfp); if (!call) return NULL; diff --git a/fs/afs/security.c b/fs/afs/security.c index 55ddce94af03..6d00d62a65ed 100644 --- a/fs/afs/security.c +++ b/fs/afs/security.c @@ -252,7 +252,7 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key, * yet. */ size++; - new = kzalloc(struct_size(new, permits, size), GFP_NOFS); + new = kzalloc_flex(*new, permits, size, GFP_NOFS); if (!new) goto out_put; diff --git a/fs/afs/server.c b/fs/afs/server.c index c4428ebddb1d..8777c566d12d 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -117,7 +117,7 @@ static struct afs_server *afs_alloc_server(struct afs_cell *cell, const uuid_t * _enter(""); - server = kzalloc(sizeof(struct afs_server), GFP_KERNEL); + server = kzalloc_obj(struct afs_server, GFP_KERNEL); if (!server) return NULL; diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c index 20d5474837df..b948df6dddc7 100644 --- a/fs/afs/server_list.c +++ b/fs/afs/server_list.c @@ -51,7 +51,7 @@ struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume, newrep++; } - slist = kzalloc(struct_size(slist, servers, nr_servers), GFP_KERNEL); + slist = kzalloc_flex(*slist, servers, nr_servers, GFP_KERNEL); if (!slist) goto error; diff --git a/fs/afs/super.c b/fs/afs/super.c index d672b7ab57ae..2b567fe5b4cb 100644 --- a/fs/afs/super.c +++ b/fs/afs/super.c @@ -502,7 +502,7 @@ static struct afs_super_info *afs_alloc_sbi(struct fs_context *fc) struct afs_fs_context *ctx = fc->fs_private; struct afs_super_info *as; - as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL); + as = kzalloc_obj(struct afs_super_info, GFP_KERNEL); if (as) { as->net_ns = get_net(fc->net_ns); as->flock_mode = ctx->flock_mode; @@ -623,7 +623,7 @@ static int afs_init_fs_context(struct fs_context *fc) struct afs_fs_context *ctx; struct afs_cell *cell; - ctx = kzalloc(sizeof(struct afs_fs_context), GFP_KERNEL); + ctx = kzalloc_obj(struct afs_fs_context, GFP_KERNEL); if (!ctx) return -ENOMEM; diff --git a/fs/afs/vl_list.c b/fs/afs/vl_list.c index 9b1c20daac53..4f430ae01646 100644 --- a/fs/afs/vl_list.c +++ b/fs/afs/vl_list.c @@ -15,8 +15,7 @@ struct afs_vlserver *afs_alloc_vlserver(const char *name, size_t name_len, struct afs_vlserver *vlserver; static atomic_t debug_ids; - vlserver = kzalloc(struct_size(vlserver, name, name_len + 1), - GFP_KERNEL); + vlserver = kzalloc_flex(*vlserver, name, name_len + 1, GFP_KERNEL); if (vlserver) { refcount_set(&vlserver->ref, 1); rwlock_init(&vlserver->lock); @@ -52,7 +51,7 @@ struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int nr_servers) { struct afs_vlserver_list *vllist; - vllist = kzalloc(struct_size(vllist, servers, nr_servers), GFP_KERNEL); + vllist = kzalloc_flex(*vllist, servers, nr_servers, GFP_KERNEL); if (vllist) { refcount_set(&vllist->ref, 1); rwlock_init(&vllist->lock); diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 3a23c0b08eb6..05abd50e4057 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -122,7 +122,7 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc, padsz = (4 - (volnamesz & 3)) & 3; reqsz = 8 + volnamesz + padsz; - entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL); + entry = kzalloc_obj(struct afs_vldb_entry, GFP_KERNEL); if (!entry) return ERR_PTR(-ENOMEM); diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 0efff3d25133..260df046143a 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -81,7 +81,7 @@ static struct afs_volume *afs_alloc_volume(struct afs_fs_context *params, struct afs_volume *volume; int ret = -ENOMEM, i; - volume = kzalloc(sizeof(struct afs_volume), GFP_KERNEL); + volume = kzalloc_obj(struct afs_volume, GFP_KERNEL); if (!volume) goto error_0; diff --git a/fs/afs/xattr.c b/fs/afs/xattr.c index e19f396aa370..2daf23af01e5 100644 --- a/fs/afs/xattr.c +++ b/fs/afs/xattr.c @@ -75,7 +75,7 @@ static bool afs_make_acl(struct afs_operation *op, { struct afs_acl *acl; - acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); + acl = kmalloc_flex(*acl, data, size, GFP_KERNEL); if (!acl) { afs_op_nomem(op); return false; @@ -157,7 +157,7 @@ static int afs_xattr_get_yfs(const struct xattr_handler *handler, else return -EOPNOTSUPP; - yacl = kzalloc(sizeof(struct yfs_acl), GFP_KERNEL); + yacl = kzalloc_obj(struct yfs_acl, GFP_KERNEL); if (!yacl) goto error; diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c index febf13a49f0b..9adc2dcde9a7 100644 --- a/fs/afs/yfsclient.c +++ b/fs/afs/yfsclient.c @@ -2048,7 +2048,7 @@ static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call) size = round_up(size, 4); if (yacl->flags & YFS_ACL_WANT_ACL) { - acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); + acl = kmalloc_flex(*acl, data, size, GFP_KERNEL); if (!acl) return -ENOMEM; yacl->acl = acl; @@ -2080,7 +2080,7 @@ static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call) size = round_up(size, 4); if (yacl->flags & YFS_ACL_WANT_VOL_ACL) { - acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); + acl = kmalloc_flex(*acl, data, size, GFP_KERNEL); if (!acl) return -ENOMEM; yacl->vol_acl = acl; |
