Thread (3 messages) 3 messages, 1 author, 2010-07-03

Re: [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write()

From: Zhang JieJing <hidden>
Date: 2010-07-03 17:35:14
Also in: linux-fsdevel
Subsystem: btrfs file system, filesystems (vfs and infrastructure), the rest · Maintainers: Chris Mason, David Sterba, Alexander Viro, Christian Brauner, Linus Torvalds

This is the improved of the former patch.
From d9c4cf7dd0e4489a31610e2fb2565ee29f0e4179 Mon Sep 17 00:00:00 2001
From: JieJing.Zhang <redacted>
Date: Sun, 4 Jul 2010 01:17:54 +0800
Subject: [PATCH] Btrfs: handle memory alloc failure in btrfs_file_aio_write()

1. kmalloc() should add a check of return valule.

2. In later code it memset zero to the allocated memory,
   so use kzalloc() instead of kmalloc() when allocation is better.

Signed-off-by: JieJing.Zhang <redacted>
---
 fs/btrfs/file.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
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)
-- 
1.7.0.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help