From: Rosen Penev <rosenp@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Phillip Lougher <phillip@squashfs.org.uk>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] Squashfs: allocate entries with cache
Date: Mon, 30 Mar 2026 14:07:03 -0700 [thread overview]
Message-ID: <20260330210703.11645-1-rosenp@gmail.com> (raw)
Use a flexible array member with kzalloc_flex to combine allocations and
simplify code slightly.
Moved struct as flexible array members require full definitions.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
fs/squashfs/cache.c | 13 +++----------
fs/squashfs/squashfs_fs_sb.h | 28 ++++++++++++++--------------
2 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
index 67abd4dff222..1231667b59e5 100644
--- a/fs/squashfs/cache.c
+++ b/fs/squashfs/cache.c
@@ -210,7 +210,6 @@ void squashfs_cache_delete(struct squashfs_cache *cache)
kfree(cache->entry[i].actor);
}
- kfree(cache->entry);
kfree(cache);
}
@@ -229,22 +228,16 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
if (entries == 0)
return NULL;
- cache = kzalloc_obj(*cache);
+ cache = kzalloc_flex(*cache, entry, entries);
if (cache == NULL) {
ERROR("Failed to allocate %s cache\n", name);
return ERR_PTR(-ENOMEM);
}
- cache->entry = kzalloc_objs(*(cache->entry), entries);
- if (cache->entry == NULL) {
- ERROR("Failed to allocate %s cache\n", name);
- goto cleanup;
- }
-
+ cache->entries = entries;
+ cache->unused = entries;
cache->curr_blk = 0;
cache->next_blk = 0;
- cache->unused = entries;
- cache->entries = entries;
cache->block_size = block_size;
cache->pages = block_size >> PAGE_SHIFT;
cache->pages = cache->pages ? cache->pages : 1;
diff --git a/fs/squashfs/squashfs_fs_sb.h b/fs/squashfs/squashfs_fs_sb.h
index c01998eec146..344b78b23f9d 100644
--- a/fs/squashfs/squashfs_fs_sb.h
+++ b/fs/squashfs/squashfs_fs_sb.h
@@ -12,20 +12,6 @@
#include "squashfs_fs.h"
-struct squashfs_cache {
- char *name;
- int entries;
- int curr_blk;
- int next_blk;
- int num_waiters;
- int unused;
- int block_size;
- int pages;
- spinlock_t lock;
- wait_queue_head_t wait_queue;
- struct squashfs_cache_entry *entry;
-};
-
struct squashfs_cache_entry {
u64 block;
int length;
@@ -40,6 +26,20 @@ struct squashfs_cache_entry {
struct squashfs_page_actor *actor;
};
+struct squashfs_cache {
+ char *name;
+ int entries;
+ int curr_blk;
+ int next_blk;
+ int num_waiters;
+ int unused;
+ int block_size;
+ int pages;
+ spinlock_t lock;
+ wait_queue_head_t wait_queue;
+ struct squashfs_cache_entry entry[] __counted_by(entries);
+};
+
struct squashfs_sb_info {
const struct squashfs_decompressor *decompressor;
int devblksize;
--
2.53.0
reply other threads:[~2026-03-30 21:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260330210703.11645-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=phillip@squashfs.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox