[PATCH 2/2] fuse: clean up null folio check in fuse_copy_folio()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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, &copy);
-			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, &copy);
+		kunmap_local(mapaddr);
+		offset += bytes_copied;
+		count -= bytes_copied;
+	}
+	if (!cs->write)
 		flush_dcache_folio(folio);
 	return 0;
 }
-- 
2.47.1





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux