mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yichong Chen <chenyichong@uniontech.com>
To: nico@fluxnic.net
Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org,
	Yichong Chen <chenyichong@uniontech.com>
Subject: [PATCH] cramfs: fix direct uncompressed full-page reads
Date: Thu,  3 Sep 2026 13:15:14 +0800	[thread overview]
Message-ID: <20260903051514.2689191-1-chenyichong@uniontech.com> (raw)

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

                 reply	other threads:[~2026-09-03  5:15 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=20260903051514.2689191-1-chenyichong@uniontech.com \
    --to=chenyichong@uniontech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nico@fluxnic.net \
    --cc=viro@zeniv.linux.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

all inboxes | Powered by JetHome®