From patchwork Thu Aug 16 12:15:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Sheng-Hui X-Patchwork-Id: 1331141 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 71005DFB34 for ; Thu, 16 Aug 2012 12:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754197Ab2HPMQH (ORCPT ); Thu, 16 Aug 2012 08:16:07 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:41152 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753855Ab2HPMQF (ORCPT ); Thu, 16 Aug 2012 08:16:05 -0400 Received: by pbbrr13 with SMTP id rr13so1502903pbb.19 for ; Thu, 16 Aug 2012 05:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=laIuVP3773vQhZPeeDzQlCZ0eT7g7JHU90hYjK6IO04=; b=tRc5NWdQRZDLL/67PUBL2GCZC7Z0jeSzwprkWUkkhNYgvggtscizfbVQ9rJQ+GTRY5 ZmxlThR+HbX6rfxF5//oFCceqM6TM8BHBGYNprlDL4b6nHdiWuH0jd1oF48cS8ru01N7 u+cbjmNtFUmLU/fpq+y/BlrInnyXyfL+XkrC37+Kic+sGXw6kJYuvazpseYgvTuGzILW wQYzqBx3BI74EXn2NkplXOm5bCokkTi+O1wHj+vXwKaltH5VtiHn3A5J7fd0f8JWR2bA WbSB9xmkVQO3h7Gp2ESVjm8KtqhFVtvm99ouSiB/xomFm35fKsWhHb10Fo3IAJyJhVPQ d5qw== Received: by 10.66.76.170 with SMTP id l10mr1872402paw.57.1345119364941; Thu, 16 Aug 2012 05:16:04 -0700 (PDT) Received: from [192.168.1.103] ([122.70.29.184]) by mx.google.com with ESMTPS id os1sm2581281pbc.31.2012.08.16.05.16.02 (version=SSLv3 cipher=OTHER); Thu, 16 Aug 2012 05:16:03 -0700 (PDT) Message-ID: <502CE47C.9070604@gmail.com> Date: Thu, 16 Aug 2012 20:15:56 +0800 From: Wang Sheng-Hui User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: Jie Liu CC: sensille@gmx.net, chris.mason@fusionio.com, linux-btrfs@vger.kernel.org Subject: Re: [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction References: <502CA7E6.8020004@gmail.com> <502CA945.602@gmx.net> <502CB573.8000107@oracle.com> In-Reply-To: <502CB573.8000107@oracle.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On 2012?08?16? 16:55, Jie Liu wrote: > On 08/16/12 16:03, Arne Jansen wrote: >> On 16.08.2012 09:57, Wang Sheng-Hui wrote: >>> For malloc may fail, we should check it before assign >>> values to the fields of struct btrfs_trans_handle *h. >>> >>> Signed-off-by: Wang Sheng-Hui >>> --- >>> transaction.h | 5 +++++ >>> 1 files changed, 5 insertions(+), 0 deletions(-) >>> >>> diff --git a/transaction.h b/transaction.h >>> index a1070e0..d4e42a1 100644 >>> --- a/transaction.h >>> +++ b/transaction.h >>> @@ -32,7 +32,12 @@ static inline struct btrfs_trans_handle * >>> btrfs_start_transaction(struct btrfs_root *root, int num_blocks) >>> { >>> struct btrfs_fs_info *fs_info = root->fs_info; >>> + > Why move down a blank line? >>> struct btrfs_trans_handle *h = malloc(sizeof(*h)); > Skip a line here would looks a bit neat. >>> + if (!h) { >>> + BUG(); >>> + return NULL; >>> + } >> a more simple way would be to write >> BUG_ON(!h); >> >>> >>> BUG_ON(root->commit_root); >>> BUG_ON(fs_info->running_transaction); >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > Patch regenerated. Please check it. Thanks, From 5a265e252e87a8a456a6615affd57dfb49900c64 Mon Sep 17 00:00:00 2001 From: Wang Sheng-Hui Date: Thu, 16 Aug 2012 20:14:32 +0800 Subject: [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction For malloc may fail, we should check it before assign values to the struct btrfs_trans_handle *h. Signed-off-by: Wang Sheng-Hui --- transaction.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/transaction.h b/transaction.h index a1070e0..e8610b1 100644 --- a/transaction.h +++ b/transaction.h @@ -34,6 +34,7 @@ btrfs_start_transaction(struct btrfs_root *root, int num_blocks) struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_trans_handle *h = malloc(sizeof(*h)); + BUG_ON(!h); BUG_ON(root->commit_root); BUG_ON(fs_info->running_transaction); fs_info->running_transaction = h;