diff mbox

Btrfs: handle kmalloc() failure in btrfs_file_aio_write()

Message ID AANLkTikZK2TBWoKS6zGTGnk830EK7fwhcjhJqfCgey55@mail.gmail.com
State Accepted
Headers show

Commit Message

JieJing.Zhang July 3, 2010, 5:35 p.m. UTC
None
diff mbox

Patch

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e354c33..961612c 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -925,7 +925,11 @@  static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 	nrptrs = min((iov_iter_count(&i) + PAGE_CACHE_SIZE - 1) /
 		     PAGE_CACHE_SIZE, PAGE_CACHE_SIZE /
 		     (sizeof(struct page *)));
-	pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
+	pages = kzalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
+	if (!pages) {
+		ret = -ENOMEM;
+		goto out;
+	}

 	/* generic_write_checks can change our pos */
 	start_pos = pos;
@@ -968,7 +972,6 @@  static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 					PAGE_CACHE_SHIFT;

 		WARN_ON(num_pages > nrptrs);
-		memset(pages, 0, sizeof(struct page *) * nrptrs);

 		ret = btrfs_delalloc_reserve_space(inode, write_bytes);
 		if (ret)