From: Joanne Koong <joannelkoong@gmail.com>
To: miklos@szeredi.hu
Cc: linux-fsdevel@vger.kernel.org, dan.carpenter@linaro.org
Subject: [PATCH 2/2] fuse: clean up null folio check in fuse_copy_folio()
Date: Fri, 23 May 2025 11:16:04 -0700 [thread overview]
Message-ID: <20250523181604.3939656-2-joannelkoong@gmail.com> (raw)
In-Reply-To: <20250523181604.3939656-1-joannelkoong@gmail.com>
In fuse_copy_folio(), the folio in *foliop will never be null.
fuse_copy_folio() is called from two places, fuse_copy_folios() and
fuse_notify_store(). In fuse_copy_folios(), the folio will never be null
since ap->num_folios always reflects how many folios are stored in the
ap->folios[] array. In fuse_notify_store(), the folio will never be null
since there's already a check for filemap_grab_folio() returning a null
folio.
Add a WARN_ON for a null folio, which allows us to simplify the logic
inside fuse_copy_folio() that otherwise checks against a null folio.
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
fs/fuse/dev.c | 50 +++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index e80cd8f2c049..54f42a92733b 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1100,14 +1100,18 @@ static int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
struct folio *folio = *foliop;
size_t size;
- if (folio) {
- size = folio_size(folio);
- if (zeroing && count < size)
- folio_zero_range(folio, 0, size);
- }
+ if (WARN_ON(!folio))
+ return 0;
+
+ size = folio_size(folio);
+ if (zeroing && count < size)
+ folio_zero_range(folio, 0, size);
while (count) {
- if (cs->write && cs->pipebufs && folio) {
+ void *mapaddr, *buf;
+ unsigned int copy, bytes_copied;
+
+ if (cs->write && cs->pipebufs) {
/*
* Can't control lifetime of pipe buffers, so always
* copy user pages.
@@ -1120,8 +1124,7 @@ static int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
return fuse_ref_folio(cs, folio, offset, count);
}
} else if (!cs->len) {
- if (cs->move_folios && folio &&
- offset == 0 && count == size) {
+ if (cs->move_folios && offset == 0 && count == size) {
err = fuse_try_move_folio(cs, foliop);
if (err <= 0)
return err;
@@ -1131,23 +1134,20 @@ static int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
return err;
}
}
- if (folio) {
- void *mapaddr = kmap_local_folio(folio, offset);
- void *buf = mapaddr;
- unsigned int copy = count;
- unsigned int bytes_copied;
-
- if (folio_test_highmem(folio) && count > PAGE_SIZE - offset_in_page(offset))
- copy = PAGE_SIZE - offset_in_page(offset);
-
- bytes_copied = fuse_copy_do(cs, &buf, ©);
- kunmap_local(mapaddr);
- offset += bytes_copied;
- count -= bytes_copied;
- } else
- offset += fuse_copy_do(cs, NULL, &count);
- }
- if (folio && !cs->write)
+
+ mapaddr = kmap_local_folio(folio, offset);
+ buf = mapaddr;
+ copy = count;
+
+ if (folio_test_highmem(folio) && count > PAGE_SIZE - offset_in_page(offset))
+ copy = PAGE_SIZE - offset_in_page(offset);
+
+ bytes_copied = fuse_copy_do(cs, &buf, ©);
+ kunmap_local(mapaddr);
+ offset += bytes_copied;
+ count -= bytes_copied;
+ }
+ if (!cs->write)
flush_dcache_folio(folio);
return 0;
}
--
2.47.1
next prev parent reply other threads:[~2025-05-23 18:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 18:16 [PATCH 1/2] fuse: Fix fuse_copy_folio() size assignation Joanne Koong
2025-05-23 18:16 ` Joanne Koong [this message]
2025-07-02 5:34 ` [PATCH 2/2] fuse: clean up null folio check in fuse_copy_folio() Miklos Szeredi
2025-07-02 22:19 ` Joanne Koong
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=20250523181604.3939656-2-joannelkoong@gmail.com \
--to=joannelkoong@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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;
as well as URLs for NNTP newsgroup(s).