summaryrefslogtreecommitdiff
path: root/fs/squashfs
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /fs/squashfs
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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/squashfs')
-rw-r--r--fs/squashfs/block.c4
-rw-r--r--fs/squashfs/cache.c4
-rw-r--r--fs/squashfs/decompressor_multi.c6
-rw-r--r--fs/squashfs/decompressor_single.c2
-rw-r--r--fs/squashfs/file.c5
-rw-r--r--fs/squashfs/lz4_wrapper.c2
-rw-r--r--fs/squashfs/lzo_wrapper.c2
-rw-r--r--fs/squashfs/page_actor.c4
-rw-r--r--fs/squashfs/super.c4
-rw-r--r--fs/squashfs/xz_wrapper.c4
-rw-r--r--fs/squashfs/zlib_wrapper.c2
-rw-r--r--fs/squashfs/zstd_wrapper.c2
12 files changed, 21 insertions, 20 deletions
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index a05e3793f93a..2d5850168026 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -88,8 +88,8 @@ static int squashfs_bio_read_cached(struct bio *fullbio,
int idx = 0;
int err = 0;
#ifdef CONFIG_SQUASHFS_COMP_CACHE_FULL
- struct folio **cache_folios = kmalloc_array(page_count,
- sizeof(*cache_folios), GFP_KERNEL | __GFP_ZERO);
+ struct folio **cache_folios = kmalloc_objs(*cache_folios, page_count,
+ GFP_KERNEL | __GFP_ZERO);
#endif
bio_for_each_folio_all(fi, fullbio) {
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
index 181260e72680..5d97b22ce297 100644
--- a/fs/squashfs/cache.c
+++ b/fs/squashfs/cache.c
@@ -229,13 +229,13 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
if (entries == 0)
return NULL;
- cache = kzalloc(sizeof(*cache), GFP_KERNEL);
+ cache = kzalloc_obj(*cache, GFP_KERNEL);
if (cache == NULL) {
ERROR("Failed to allocate %s cache\n", name);
return ERR_PTR(-ENOMEM);
}
- cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL);
+ cache->entry = kzalloc_objs(*(cache->entry), entries, GFP_KERNEL);
if (cache->entry == NULL) {
ERROR("Failed to allocate %s cache\n", name);
goto cleanup;
diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_multi.c
index 416c53eedbd1..4d7bc620bef5 100644
--- a/fs/squashfs/decompressor_multi.c
+++ b/fs/squashfs/decompressor_multi.c
@@ -65,7 +65,7 @@ static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
struct decomp_stream *decomp_strm = NULL;
int err = -ENOMEM;
- stream = kzalloc(sizeof(*stream), GFP_KERNEL);
+ stream = kzalloc_obj(*stream, GFP_KERNEL);
if (!stream)
goto out;
@@ -80,7 +80,7 @@ static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
* we could always fall back to default decompressor and
* file system works.
*/
- decomp_strm = kmalloc(sizeof(*decomp_strm), GFP_KERNEL);
+ decomp_strm = kmalloc_obj(*decomp_strm, GFP_KERNEL);
if (!decomp_strm)
goto out;
@@ -148,7 +148,7 @@ static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk,
goto wait;
/* Let's allocate new decomp */
- decomp_strm = kmalloc(sizeof(*decomp_strm), GFP_KERNEL);
+ decomp_strm = kmalloc_obj(*decomp_strm, GFP_KERNEL);
if (!decomp_strm)
goto wait;
diff --git a/fs/squashfs/decompressor_single.c b/fs/squashfs/decompressor_single.c
index 6f161887710b..1f1597104ca8 100644
--- a/fs/squashfs/decompressor_single.c
+++ b/fs/squashfs/decompressor_single.c
@@ -30,7 +30,7 @@ static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
struct squashfs_stream *stream;
int err = -ENOMEM;
- stream = kmalloc(sizeof(*stream), GFP_KERNEL);
+ stream = kmalloc_obj(*stream, GFP_KERNEL);
if (stream == NULL)
goto out;
diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index 4be92206e755..8b45020b4a13 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -103,8 +103,9 @@ static struct meta_index *empty_meta_index(struct inode *inode, int offset,
* mount time but doing it here means it is allocated only
* if a 'large' file is read.
*/
- msblk->meta_index = kcalloc(SQUASHFS_META_SLOTS,
- sizeof(*(msblk->meta_index)), GFP_KERNEL);
+ msblk->meta_index = kzalloc_objs(*(msblk->meta_index),
+ SQUASHFS_META_SLOTS,
+ GFP_KERNEL);
if (msblk->meta_index == NULL) {
ERROR("Failed to allocate meta_index\n");
goto failed;
diff --git a/fs/squashfs/lz4_wrapper.c b/fs/squashfs/lz4_wrapper.c
index 49797729f143..e482757d8f2c 100644
--- a/fs/squashfs/lz4_wrapper.c
+++ b/fs/squashfs/lz4_wrapper.c
@@ -54,7 +54,7 @@ static void *lz4_init(struct squashfs_sb_info *msblk, void *buff)
int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
struct squashfs_lz4 *stream;
- stream = kzalloc(sizeof(*stream), GFP_KERNEL);
+ stream = kzalloc_obj(*stream, GFP_KERNEL);
if (stream == NULL)
goto failed;
stream->input = vmalloc(block_size);
diff --git a/fs/squashfs/lzo_wrapper.c b/fs/squashfs/lzo_wrapper.c
index d216aeefa865..961fda720c14 100644
--- a/fs/squashfs/lzo_wrapper.c
+++ b/fs/squashfs/lzo_wrapper.c
@@ -29,7 +29,7 @@ static void *lzo_init(struct squashfs_sb_info *msblk, void *buff)
{
int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
- struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
+ struct squashfs_lzo *stream = kzalloc_obj(*stream, GFP_KERNEL);
if (stream == NULL)
goto failed;
stream->input = vmalloc(block_size);
diff --git a/fs/squashfs/page_actor.c b/fs/squashfs/page_actor.c
index 2b3e807d4dea..3d8f0225e240 100644
--- a/fs/squashfs/page_actor.c
+++ b/fs/squashfs/page_actor.c
@@ -43,7 +43,7 @@ static void cache_finish_page(struct squashfs_page_actor *actor)
struct squashfs_page_actor *squashfs_page_actor_init(void **buffer,
int pages, int length)
{
- struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
+ struct squashfs_page_actor *actor = kmalloc_obj(*actor, GFP_KERNEL);
if (actor == NULL)
return NULL;
@@ -110,7 +110,7 @@ static void direct_finish_page(struct squashfs_page_actor *actor)
struct squashfs_page_actor *squashfs_page_actor_init_special(struct squashfs_sb_info *msblk,
struct page **page, int pages, int length, loff_t start_index)
{
- struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
+ struct squashfs_page_actor *actor = kmalloc_obj(*actor, GFP_KERNEL);
if (actor == NULL)
return NULL;
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 4465cf05603a..69217e752bc5 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -196,7 +196,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
return -EINVAL;
}
- sb->s_fs_info = kzalloc(sizeof(*msblk), GFP_KERNEL);
+ sb->s_fs_info = kzalloc_obj(*msblk, GFP_KERNEL);
if (sb->s_fs_info == NULL) {
ERROR("Failed to allocate squashfs_sb_info\n");
return -ENOMEM;
@@ -549,7 +549,7 @@ static int squashfs_init_fs_context(struct fs_context *fc)
{
struct squashfs_mount_opts *opts;
- opts = kzalloc(sizeof(*opts), GFP_KERNEL);
+ opts = kzalloc_obj(*opts, GFP_KERNEL);
if (!opts)
return -ENOMEM;
diff --git a/fs/squashfs/xz_wrapper.c b/fs/squashfs/xz_wrapper.c
index 6c49481a2f8c..d258f4726d2e 100644
--- a/fs/squashfs/xz_wrapper.c
+++ b/fs/squashfs/xz_wrapper.c
@@ -42,7 +42,7 @@ static void *squashfs_xz_comp_opts(struct squashfs_sb_info *msblk,
struct comp_opts *opts;
int err = 0, n;
- opts = kmalloc(sizeof(*opts), GFP_KERNEL);
+ opts = kmalloc_obj(*opts, GFP_KERNEL);
if (opts == NULL) {
err = -ENOMEM;
goto out2;
@@ -84,7 +84,7 @@ static void *squashfs_xz_init(struct squashfs_sb_info *msblk, void *buff)
struct squashfs_xz *stream;
int err;
- stream = kmalloc(sizeof(*stream), GFP_KERNEL);
+ stream = kmalloc_obj(*stream, GFP_KERNEL);
if (stream == NULL) {
err = -ENOMEM;
goto failed;
diff --git a/fs/squashfs/zlib_wrapper.c b/fs/squashfs/zlib_wrapper.c
index cbb7afe7bc46..899629c54d97 100644
--- a/fs/squashfs/zlib_wrapper.c
+++ b/fs/squashfs/zlib_wrapper.c
@@ -23,7 +23,7 @@
static void *zlib_init(struct squashfs_sb_info *dummy, void *buff)
{
- z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
+ z_stream *stream = kmalloc_obj(z_stream, GFP_KERNEL);
if (stream == NULL)
goto failed;
stream->workspace = vmalloc(zlib_inflate_workspacesize());
diff --git a/fs/squashfs/zstd_wrapper.c b/fs/squashfs/zstd_wrapper.c
index 0e407c4d8b3b..632560e4d6b0 100644
--- a/fs/squashfs/zstd_wrapper.c
+++ b/fs/squashfs/zstd_wrapper.c
@@ -28,7 +28,7 @@ struct workspace {
static void *zstd_init(struct squashfs_sb_info *msblk, void *buff)
{
- struct workspace *wksp = kmalloc(sizeof(*wksp), GFP_KERNEL);
+ struct workspace *wksp = kmalloc_obj(*wksp, GFP_KERNEL);
if (wksp == NULL)
goto failed;