All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arne Jansen <sensille@gmx.net>
To: Wang Sheng-Hui <shhuiw@gmail.com>
Cc: chris.mason@fusionio.com, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
Date: Thu, 16 Aug 2012 10:03:17 +0200	[thread overview]
Message-ID: <502CA945.602@gmx.net> (raw)
In-Reply-To: <502CA7E6.8020004@gmail.com>

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 <shhuiw@gmail.com>
> ---
>  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;
> +
>  	struct btrfs_trans_handle *h = malloc(sizeof(*h));
> +	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);


  reply	other threads:[~2012-08-16  8:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-16  7:57 [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction Wang Sheng-Hui
2012-08-16  8:03 ` Arne Jansen [this message]
2012-08-16  8:55   ` Jie Liu
2012-08-16 12:15     ` Wang Sheng-Hui

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=502CA945.602@gmx.net \
    --to=sensille@gmx.net \
    --cc=chris.mason@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=shhuiw@gmail.com \
    /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.