All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang JieJing <kzjeef@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, Chris Mason <chris.mason@oracle.com>
Subject: Re: [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write()
Date: Sun, 4 Jul 2010 01:35:14 +0800	[thread overview]
Message-ID: <AANLkTikZK2TBWoKS6zGTGnk830EK7fwhcjhJqfCgey55@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinv_7JGRhI8PtnmPUY3yqcPJBV7-ENPsCfYJPkb@mail.gmail.com>

This is the improved of the former patch.

>From d9c4cf7dd0e4489a31610e2fb2565ee29f0e4179 Mon Sep 17 00:00:00 2001
From: JieJing.Zhang <kzjeef@gmail.com>
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 <kzjeef@gmail.com>
---
 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

      reply	other threads:[~2010-07-03 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-19 18:13 [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write() JieJing.Zhang
2010-06-20  4:56 ` Zhang JieJing
2010-07-03 17:35   ` Zhang JieJing [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTikZK2TBWoKS6zGTGnk830EK7fwhcjhJqfCgey55@mail.gmail.com \
    --to=kzjeef@gmail.com \
    --cc=chris.mason@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.