diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 5fa453b..7aa60db 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1170,6 +1170,7 @@ retry:
 	if (IS_ERR(handle)) {
 		unlock_page(page);
 		page_cache_release(page);
+		*pagep = NULL;
 		ret = PTR_ERR(handle);
 		goto out;
 	}
@@ -1187,6 +1188,7 @@ write_begin_failed:
 		ext3_journal_stop(handle);
 		unlock_page(page);
 		page_cache_release(page);
+		*pagep = NULL;
 		/*
 		 * block_write_begin may have instantiated a few blocks
 		 * outside i_size.  Trim these off again. Don't need
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 658c4a7..0581c48 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1388,6 +1388,7 @@ retry:
 		unlock_page(page);
 		ext4_journal_stop(handle);
 		page_cache_release(page);
+		*pagep = NULL;
 		/*
 		 * block_write_begin may have instantiated a few blocks
 		 * outside i_size.  Trim these off again. Don't need
