From patchwork Tue Feb 15 12:01:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshinori Sano X-Patchwork-Id: 558681 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1FC2BY5015385 for ; Tue, 15 Feb 2011 12:02:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754638Ab1BOMCJ (ORCPT ); Tue, 15 Feb 2011 07:02:09 -0500 Received: from mail-px0-f174.google.com ([209.85.212.174]:48169 "EHLO mail-px0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754524Ab1BOMCI (ORCPT ); Tue, 15 Feb 2011 07:02:08 -0500 Received: by pxi15 with SMTP id 15so11443pxi.19 for ; Tue, 15 Feb 2011 04:02:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=WKtcSECKrDck2On94JXVchuLT3j1BO79jaw3m04M23I=; b=GrGMNcAlvrE51W6gr1zr7G6Pc1rzEfrTWym4cEAY3MwzsEdV4MuzeOL5N621yZKIvZ TsZ703H+agVdfNzxBnp2XFlh1y92Q1wHxGCp83TP+iwX9BCWUXFCDUzwSN4qBZHA1duq g7IsliIyAmnyfNSLQCk317DDZOGNTifqvYAWM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=eaFMs4KtR8Hkyg82nCTzn3WwIgVsJH5WWIu6viwvrDcQNdL696XVll2827uswG2Hj1 vrzeDD6OUjfIMlxHGKyeoD+u3Gz35NaZ+Jzqcd6Kxoh+P04SlNV5+Q2t0YeWBAlUKWCd 69ZtbdvMrKSZan6gOdUVjMOMAZtIddY/T64+I= Received: by 10.142.237.20 with SMTP id k20mr4144106wfh.449.1297771327878; Tue, 15 Feb 2011 04:02:07 -0800 (PST) Received: from localhost (EM114-51-171-185.pool.e-mobile.ne.jp [114.51.171.185]) by mx.google.com with ESMTPS id z1sm110305wfd.21.2011.02.15.04.02.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Feb 2011 04:02:07 -0800 (PST) From: Yoshinori Sano To: linux-btrfs@vger.kernel.org Cc: Yoshinori Sano Subject: [PATCH] Btrfs: fix uncheck memory allocations Date: Tue, 15 Feb 2011 21:01:42 +0900 Message-Id: <1297771302-28297-1-git-send-email-yoshinori.sano@gmail.com> X-Mailer: git-send-email 1.7.1 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.6 (demeter1.kernel.org [140.211.167.41]); Tue, 15 Feb 2011 12:02:12 +0000 (UTC) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 4d2110e..992a4b9 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -340,6 +340,8 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, WARN_ON(start & ((u64)PAGE_CACHE_SIZE - 1)); cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS); + if (!cb) + return -ENOMEM; atomic_set(&cb->pending_bios, 0); cb->errors = 0; cb->inode = inode; @@ -354,6 +356,10 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS); + if(!bio) { + kfree(cb); + return -ENOMEM; + } bio->bi_private = cb; bio->bi_end_io = end_compressed_bio_write; atomic_inc(&cb->pending_bios); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a7aaa10..3c6d0f2 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -6931,6 +6931,10 @@ static noinline int get_new_locations(struct inode *reloc_inode, struct disk_extent *old = exts; max *= 2; exts = kzalloc(sizeof(*exts) * max, GFP_NOFS); + if (!exts) { + ret = -ENOMEM; + goto out; + } memcpy(exts, old, sizeof(*exts) * nr); if (old != *extents) kfree(old); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8d392ed..12a5a40 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -287,6 +287,7 @@ static noinline int add_async_extent(struct async_cow *cow, struct async_extent *async_extent; async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); + BUG_ON(!async_extent); async_extent->start = start; async_extent->ram_size = ram_size; async_extent->compressed_size = compressed_size; @@ -384,6 +385,7 @@ again: (BTRFS_I(inode)->force_compress))) { WARN_ON(pages); pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); + BUG_ON(!pages); if (BTRFS_I(inode)->force_compress) compress_type = BTRFS_I(inode)->force_compress;