From patchwork Sat Jul 3 17:35:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "JieJing.Zhang" X-Patchwork-Id: 110042 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o63HZOK5002944 for ; Sat, 3 Jul 2010 17:35:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755239Ab0GCRfR (ORCPT ); Sat, 3 Jul 2010 13:35:17 -0400 Received: from mail-qy0-f174.google.com ([209.85.216.174]:56008 "EHLO mail-qy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754864Ab0GCRfP (ORCPT ); Sat, 3 Jul 2010 13:35:15 -0400 Received: by qyk35 with SMTP id 35so808868qyk.19 for ; Sat, 03 Jul 2010 10:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=FYhgOW4GEvIuOYwNZ4gLQ2ggPiyq0vgq/JwUgYulLKQ=; b=YOBn+UMeJf1t3RnmIyDUfaK7iorMHwR0HsCEhRt9PHtl6Br6sKpaaZBCaiQURSVUgN fN3mMuUTDI9lwJnyqa5lrumdnw+j8RZNa319thGmMkI11q5CLLgxEwpmfayQtdhOE3GV dAxAHp397kkESa+5x/Ht14k6yLOkoNRPVR3xo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=t/RbmtVxQbfb1xsnfslHtytgkaDVFqIxvbTHNv5fH0hkXpp1HmzAefkUcEXcQDoOEb hmTaxVljnCMjHLNrM8ULHdYxsR6qwbndXA6RKk7bWAWLeeow2RxfWx2FM7bRSGAEcW7k wZWkauzjru/vzLqlPgBcYGqMaLLzsuyupbAWc= MIME-Version: 1.0 Received: by 10.224.119.17 with SMTP id x17mr263656qaq.242.1278178514588; Sat, 03 Jul 2010 10:35:14 -0700 (PDT) Received: by 10.229.89.5 with HTTP; Sat, 3 Jul 2010 10:35:14 -0700 (PDT) In-Reply-To: References: <1276971194-24572-1-git-send-email-kzjeef@gmail.com> Date: Sun, 4 Jul 2010 01:35:14 +0800 Message-ID: Subject: Re: [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write() From: Zhang JieJing To: linux-btrfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Chris Mason Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 03 Jul 2010 17:35:25 +0000 (UTC) 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)