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/overlayfs | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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/overlayfs')
| -rw-r--r-- | fs/overlayfs/file.c | 2 | ||||
| -rw-r--r-- | fs/overlayfs/namei.c | 2 | ||||
| -rw-r--r-- | fs/overlayfs/params.c | 6 | ||||
| -rw-r--r-- | fs/overlayfs/readdir.c | 6 | ||||
| -rw-r--r-- | fs/overlayfs/super.c | 4 | ||||
| -rw-r--r-- | fs/overlayfs/util.c | 4 |
6 files changed, 12 insertions, 12 deletions
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 8269431ba3c6..7f7a2c2a7937 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -96,7 +96,7 @@ struct ovl_file { struct ovl_file *ovl_file_alloc(struct file *realfile) { - struct ovl_file *of = kzalloc(sizeof(struct ovl_file), GFP_KERNEL); + struct ovl_file *of = kzalloc_obj(struct ovl_file, GFP_KERNEL); if (unlikely(!of)) return NULL; diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index afb7019fd43a..f30b81ee0d9b 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -481,7 +481,7 @@ int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, goto invalid; if (!*stackp) - *stackp = kmalloc(sizeof(struct ovl_path), GFP_KERNEL); + *stackp = kmalloc_obj(struct ovl_path, GFP_KERNEL); if (!*stackp) { dput(origin); return -ENOMEM; diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 63b7346c5ee1..af735a0c310a 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -777,7 +777,7 @@ int ovl_init_fs_context(struct fs_context *fc) struct ovl_fs_context *ctx; struct ovl_fs *ofs; - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); + ctx = kzalloc_obj(*ctx, GFP_KERNEL_ACCOUNT); if (!ctx) return -ENOMEM; @@ -785,12 +785,12 @@ int ovl_init_fs_context(struct fs_context *fc) * By default we allocate for three lower layers. It's likely * that it'll cover most users. */ - ctx->lower = kmalloc_array(3, sizeof(*ctx->lower), GFP_KERNEL_ACCOUNT); + ctx->lower = kmalloc_objs(*ctx->lower, 3, GFP_KERNEL_ACCOUNT); if (!ctx->lower) goto out_err; ctx->capacity = 3; - ofs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL); + ofs = kzalloc_obj(struct ovl_fs, GFP_KERNEL); if (!ofs) goto out_err; diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c index bb09142b4e15..953c2cdca1b4 100644 --- a/fs/overlayfs/readdir.c +++ b/fs/overlayfs/readdir.c @@ -180,7 +180,7 @@ static struct ovl_cache_entry *ovl_cache_entry_new(struct ovl_readdir_data *rdd, { struct ovl_cache_entry *p; - p = kmalloc(struct_size(p, name, len + 1), GFP_KERNEL); + p = kmalloc_flex(*p, name, len + 1, GFP_KERNEL); if (!p) return NULL; @@ -493,7 +493,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) } ovl_set_dir_cache(d_inode(dentry), NULL); - cache = kzalloc(sizeof(struct ovl_dir_cache), GFP_KERNEL); + cache = kzalloc_obj(struct ovl_dir_cache, GFP_KERNEL); if (!cache) return ERR_PTR(-ENOMEM); @@ -706,7 +706,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path) ovl_dir_cache_free(inode); ovl_set_dir_cache(inode, NULL); - cache = kzalloc(sizeof(struct ovl_dir_cache), GFP_KERNEL); + cache = kzalloc_obj(struct ovl_dir_cache, GFP_KERNEL); if (!cache) return ERR_PTR(-ENOMEM); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index c9f166a1390a..f3a39b7703f5 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -1031,7 +1031,7 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs, unsigned int i; size_t nr_merged_lower; - ofs->fs = kcalloc(ctx->nr + 2, sizeof(struct ovl_sb), GFP_KERNEL); + ofs->fs = kzalloc_objs(struct ovl_sb, ctx->nr + 2, GFP_KERNEL); if (ofs->fs == NULL) return -ENOMEM; @@ -1393,7 +1393,7 @@ static int ovl_fill_super_creds(struct fs_context *fc, struct super_block *sb) } err = -ENOMEM; - layers = kcalloc(ctx->nr + 1, sizeof(struct ovl_layer), GFP_KERNEL); + layers = kzalloc_objs(struct ovl_layer, ctx->nr + 1, GFP_KERNEL); if (!layers) return err; diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 94986d11a166..a28524e83662 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -113,7 +113,7 @@ bool ovl_verify_lower(struct super_block *sb) struct ovl_path *ovl_stack_alloc(unsigned int n) { - return kcalloc(n, sizeof(struct ovl_path), GFP_KERNEL); + return kzalloc_objs(struct ovl_path, n, GFP_KERNEL); } void ovl_stack_cpy(struct ovl_path *dst, struct ovl_path *src, unsigned int n) @@ -143,7 +143,7 @@ struct ovl_entry *ovl_alloc_entry(unsigned int numlower) { struct ovl_entry *oe; - oe = kzalloc(struct_size(oe, __lowerstack, numlower), GFP_KERNEL); + oe = kzalloc_flex(*oe, __lowerstack, numlower, GFP_KERNEL); if (oe) oe->__numlower = numlower; |
