diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0d424d7ac02b0a30f98e713bb10403e90ced51b5..e274e9c1171f9095829aff07224dfff650a85ed2 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2563,7 +2563,7 @@ static int ext4_writepages(struct address_space *mapping,
 			break;
 	}
 	blk_finish_plug(&plug);
-	if (!ret && !cycled) {
+	if (!ret && !cycled && wbc->nr_to_write > 0) {
 		cycled = 1;
 		mpd.last_page = writeback_index - 1;
 		mpd.first_page = 0;
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index c081e34f717f6903492acd3c4bc92d26dc888e7e..03e9bebba1989ef20263fbd1656959b764927b03 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1350,6 +1350,8 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
 				    s_min_extra_isize) {
 					tried_min_extra_isize++;
 					new_extra_isize = s_min_extra_isize;
+					kfree(is); is = NULL;
+					kfree(bs); bs = NULL;
 					goto retry;
 				}
 				error = -1;