diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-21 10:49:23 +0300 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 12:02:28 +0300 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /fs/cachefiles | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-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 'fs/cachefiles')
| -rw-r--r-- | fs/cachefiles/daemon.c | 2 | ||||
| -rw-r--r-- | fs/cachefiles/io.c | 4 | ||||
| -rw-r--r-- | fs/cachefiles/ondemand.c | 4 | ||||
| -rw-r--r-- | fs/cachefiles/volume.c | 2 |
4 files changed, 6 insertions, 6 deletions
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index 1806bff8e59b..99795864bcb3 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -102,7 +102,7 @@ static int cachefiles_daemon_open(struct inode *inode, struct file *file) return -EBUSY; /* allocate a cache record */ - cache = kzalloc(sizeof(struct cachefiles_cache), GFP_KERNEL); + cache = kzalloc_obj(struct cachefiles_cache, GFP_KERNEL); if (!cache) { cachefiles_open = 0; return -ENOMEM; diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c index 3e0576d9db1d..7b9d547ecee6 100644 --- a/fs/cachefiles/io.c +++ b/fs/cachefiles/io.c @@ -132,7 +132,7 @@ static int cachefiles_read(struct netfs_cache_resources *cres, } ret = -ENOMEM; - ki = kzalloc(sizeof(struct cachefiles_kiocb), GFP_KERNEL); + ki = kzalloc_obj(struct cachefiles_kiocb, GFP_KERNEL); if (!ki) goto presubmission_error; @@ -298,7 +298,7 @@ int __cachefiles_write(struct cachefiles_object *object, file, file_inode(file)->i_ino, start_pos, len, i_size_read(file_inode(file))); - ki = kzalloc(sizeof(struct cachefiles_kiocb), GFP_KERNEL); + ki = kzalloc_obj(struct cachefiles_kiocb, GFP_KERNEL); if (!ki) { if (term_func) term_func(term_func_priv, -ENOMEM); diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index a7ed86fa98bb..b251fff2bed0 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -734,8 +734,8 @@ int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object, if (!cachefiles_in_ondemand_mode(volume->cache)) return 0; - object->ondemand = kzalloc(sizeof(struct cachefiles_ondemand_info), - GFP_KERNEL); + object->ondemand = kzalloc_obj(struct cachefiles_ondemand_info, + GFP_KERNEL); if (!object->ondemand) return -ENOMEM; diff --git a/fs/cachefiles/volume.c b/fs/cachefiles/volume.c index 90ba926f488e..655de0cef530 100644 --- a/fs/cachefiles/volume.c +++ b/fs/cachefiles/volume.c @@ -28,7 +28,7 @@ void cachefiles_acquire_volume(struct fscache_volume *vcookie) _enter(""); - volume = kzalloc(sizeof(struct cachefiles_volume), GFP_KERNEL); + volume = kzalloc_obj(struct cachefiles_volume, GFP_KERNEL); if (!volume) return; volume->vcookie = vcookie; |
