mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cramfs: fix direct uncompressed full-page reads
@ 2026-09-03  5:15 Yichong Chen
  0 siblings, 0 replies; only message in thread
From: Yichong Chen @ 2026-09-03  5:15 UTC (permalink / raw)
  To: nico; +Cc: viro, linux-kernel, Yichong Chen

For direct uncompressed cramfs blocks, the block size is PAGE_SIZE except
for the last block, where it is capped by the file size.

When the file size is exactly page-aligned, offset_in_page(i_size)
returns 0. The current last-block handling then turns the final full page
into a zero-length block, so cramfs_read_folio() treats it as a hole and
returns zero-filled data instead of the stored page.

Keep PAGE_SIZE for a page-aligned final block, and only shorten the block
when the last page is partial.

Fixes: fd4f6f2a78ae ("cramfs: implement uncompressed and arbitrary data block positioning")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
 fs/cramfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index d4cd03f4f60d..371b4c421d86 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -853,9 +853,9 @@ static int cramfs_read_folio(struct file *file, struct folio *folio)
 			if (uncompressed) {
 				block_len = PAGE_SIZE;
 				/* if last block: cap to file length */
-				if (folio->index == maxblock - 1)
-					block_len =
-						offset_in_page(inode->i_size);
+				if (folio->index == maxblock - 1 &&
+				    offset_in_page(inode->i_size))
+					block_len = offset_in_page(inode->i_size);
 			} else {
 				block_len = *(u16 *)
 					cramfs_read(sb, block_start, 2);
-- 
2.51.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-03  5:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03  5:15 [PATCH] cramfs: fix direct uncompressed full-page reads Yichong Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®