From nobody Fri Apr 3 10:17:50 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44966396571 for ; Mon, 30 Mar 2026 21:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774904843; cv=none; b=ChWoSck3oZG/ep/6+tiyUX3A3LiPQcrHbxMBCKr3koDpHCfj+J6jWSm00X1Ilq54bk/e0ml6VsNFQQeNkVLnF1KJGEbdBluqncHa4s7dH1qx967bTJdYs7XmTFwtcFYvAgELkxczaO0OH5zeyQoDw5APprRFGFzko8geUKcZrwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774904843; c=relaxed/simple; bh=QpZtDQ2tAWRJHE/3K+afYt1HU8XGkF0gE5uP3vEh0L8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Fyh/KcBDbEwubQCUuL1CmtBP+fIbOSxiLkSnyUIOrE3skezBu9DkoMzNPMQyLpkklkGAyRcMamJiL6le+460oMb6MsVgNgmy+OwjMNi6muaRtublUWPNOCpmbT3GDn803NaUhI3SRtbiGdYceSDQV0lSepSNK98+prO2ZXDrrTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KFZlBjcf; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KFZlBjcf" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-82a655cfab5so4618010b3a.1 for ; Mon, 30 Mar 2026 14:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774904841; x=1775509641; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wfYhu3goSRUoYF3KrZUoCVBHuxcKznqPMmyxD8YhPO8=; b=KFZlBjcf/RBddG0PvIj2nJlRfigIP1YZGGiGlPLG3Hl7gQbTHPxgx8KQMPGC3P7MEr D6tnoVvNjh+jjWimGOmnxYNFV78qGlOuarQiUSi9YWoc/otS14QTDwcHlucs8GChr6xw WUgjyt7KTNI5/bXuuxf+trYAeIs0GDAjt9Tk3xVa9nfd5m35sr4TlWd2BoYd+/MiBHQM kzzVdteWWl6Z+SkKiY6R4vm1qZPWx5CLWPtYBfLkgL3+z3I1vSDjWxkSXKQ58uGcyOj4 47QJzrDY1lgrYEOeArq5o3AGhr5frWQ7UiCw8p4LtEh5fq9r63cn55hwGX4SHzWDtJwE kc1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774904841; x=1775509641; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wfYhu3goSRUoYF3KrZUoCVBHuxcKznqPMmyxD8YhPO8=; b=CT4emthyFCvhBHboM0WySKJ3bGToLTVwEfQzxYejTVkGH3zazU1gL0bGLz8beGNlEc 8NEgXNktPKBY1WNC4SSWwVIfCbALJ7dRnrXtnw0BGFS9/Y0MvDDP2zissOzzaGSz8W4v nt+iFswiqWbWa2OesGPs2DdjELRmvt6ToT3jpZcfbDDuFCP23OHGAGBFTDYDNbpuEWHx /S3mZ3mLSI6MWw7uPr3dhyf5abAHND2GR02lH8JXQXCXwp3Aw1ApxreYBb0b6NF53yWf ClmkJCnolDGNP84FHXtrPYUsb705B0WWrmoh2DOMIuKiw2/wB+mIvZp7mJXv4tye0zw0 uFeg== X-Gm-Message-State: AOJu0YxXvQg2eVZGULVoaNcDvw/keErXB/tkHZq5fzcH4Hqy59clXpiN fgtRKQgNcdiaA5cmTjbQzUCdpayPsVlIVMBV3zKxgVETh8/ZX74q8xZgfqEFSQ== X-Gm-Gg: ATEYQzwuPtgLcbaBLobe8u6o6WO6rKN9LvZM7iLvQYwOhshhK+dC10ePsQOoftpAnjM d+c7RWlsWnz38on4WrDx8e0aP7m1dvAyxZQyVlmRhzF856ubm3b4shBejC7r1rvOY6pbVczzIqX ucXMV5NOfPyRA67G9M85JTnTLKdeIZc/3Pcu1og4d9Lo79n4U5FIng/at53YkoPkjYXjJthWeWB yjXIXVKnO2TnYldny9gDsDzRfsGNBXgkkKQw9VFcps0r8HwRAd7b/1NMZKr/p800Du0X2mdW4Qk CCl2kgCYdegsIEQoueXqunljP5GN9XPEykhAfFxZy2TyUqGCJoHOu8f6xuqijUBGOQsxc72zjks 92NBvLLD1If35KPFLKeXi9fXxmn3RFWUuu4FujpbLBGN0FluuoZ0c+Fb9XXnv5U+SceJkrj97cS UjyjjLaSI5lDuAGu0ZUOBPtlO38RsOq3foTM4dK1xs15I6mVfgQCPqHtw= X-Received: by 2002:a05:6a00:4091:b0:81f:3cac:38a1 with SMTP id d2e1a72fcca58-82c95c19210mr12662926b3a.6.1774904840991; Mon, 30 Mar 2026 14:07:20 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82caf97abfesm7146335b3a.1.2026.03.30.14.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 14:07:20 -0700 (PDT) From: Rosen Penev To: linux-kernel@vger.kernel.org Cc: Phillip Lougher , Kees Cook , "Gustavo A. R. Silva" , 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 Message-ID: <20260330210703.11645-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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); } =20 - kfree(cache->entry); kfree(cache); } =20 @@ -229,22 +228,16 @@ struct squashfs_cache *squashfs_cache_init(char *name= , int entries, if (entries =3D=3D 0) return NULL; =20 - cache =3D kzalloc_obj(*cache); + cache =3D kzalloc_flex(*cache, entry, entries); if (cache =3D=3D NULL) { ERROR("Failed to allocate %s cache\n", name); return ERR_PTR(-ENOMEM); } =20 - cache->entry =3D kzalloc_objs(*(cache->entry), entries); - if (cache->entry =3D=3D NULL) { - ERROR("Failed to allocate %s cache\n", name); - goto cleanup; - } - + cache->entries =3D entries; + cache->unused =3D entries; cache->curr_blk =3D 0; cache->next_blk =3D 0; - cache->unused =3D entries; - cache->entries =3D entries; cache->block_size =3D block_size; cache->pages =3D block_size >> PAGE_SHIFT; cache->pages =3D 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 @@ =20 #include "squashfs_fs.h" =20 -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; }; =20 +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; --=20 2.53.0