diff mbox series

fuse: fixed WARNING:at_fs/fuse/file.c:#tree_insert[fuse]

Message ID b80b820d-8cec-fdb2-546c-1085cb3a9db8@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series fuse: fixed WARNING:at_fs/fuse/file.c:#tree_insert[fuse] | expand

Commit Message

Vasily Averin June 15, 2020, 7:19 a.m. UTC
kernel test robot <rong.a.chen@intel.com> detected warning after apply of 
6b2fb79963fb ("fuse: optimize writepages search")

WARNING: CPU: 1 PID: 17211 at fs/fuse/file.c:1728 tree_insert+0xab/0xc0 [fuse]
RIP: 0010:tree_insert+0xab/0xc0 [fuse]
Call Trace:
 fuse_writepages_fill+0x5da/0x6a0 [fuse]
 write_cache_pages+0x171/0x470
 fuse_writepages+0x8a/0x100 [fuse]
 do_writepages+0x43/0xe0

It was triggered by WARN_ON(!wpa->ia.ap.num_pages) 

Though fuse_writepages_fill() calls tree_insert() with
wpa->ia.ap.num_pages = 0 and increments it a bit later.

Fixes: 6b2fb79963fb ("fuse: optimize writepages search")
Reported-by: kernel test robot <rong.a.chen@intel.com>
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 fs/fuse/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index e573b0c..1771396 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1677,11 +1677,11 @@  void fuse_flush_writepages(struct inode *inode)
 static void tree_insert(struct rb_root *root, struct fuse_writepage_args *wpa)
 {
 	pgoff_t idx_from = wpa->ia.write.in.offset >> PAGE_SHIFT;
-	pgoff_t idx_to = idx_from + wpa->ia.ap.num_pages - 1;
+	pgoff_t idx_to = idx_from + (wpa->ia.ap.num_pages ?
+				wpa->ia.ap.num_pages - 1 : 0);
 	struct rb_node **p = &root->rb_node;
 	struct rb_node  *parent = NULL;
 
-	WARN_ON(!wpa->ia.ap.num_pages);
 	while (*p) {
 		struct fuse_writepage_args *curr;
 		pgoff_t curr_index;