linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
@ 2012-08-16  7:57 Wang Sheng-Hui
  2012-08-16  8:03 ` Arne Jansen
  0 siblings, 1 reply; 4+ messages in thread
From: Wang Sheng-Hui @ 2012-08-16  7:57 UTC (permalink / raw)
  To: chris.mason, linux-btrfs

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;
+	}
 
 	BUG_ON(root->commit_root);
 	BUG_ON(fs_info->running_transaction);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
  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
  2012-08-16  8:55   ` Jie Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Arne Jansen @ 2012-08-16  8:03 UTC (permalink / raw)
  To: Wang Sheng-Hui; +Cc: chris.mason, linux-btrfs

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);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
  2012-08-16  8:03 ` Arne Jansen
@ 2012-08-16  8:55   ` Jie Liu
  2012-08-16 12:15     ` Wang Sheng-Hui
  0 siblings, 1 reply; 4+ messages in thread
From: Jie Liu @ 2012-08-16  8:55 UTC (permalink / raw)
  To: Wang Sheng-Hui; +Cc: sensille, chris.mason, linux-btrfs

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 <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;
>> +
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
  2012-08-16  8:55   ` Jie Liu
@ 2012-08-16 12:15     ` Wang Sheng-Hui
  0 siblings, 0 replies; 4+ messages in thread
From: Wang Sheng-Hui @ 2012-08-16 12:15 UTC (permalink / raw)
  To: Jie Liu; +Cc: sensille, chris.mason, linux-btrfs

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 <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;
>>> +
> 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 <shhuiw@gmail.com>
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 <shhuiw@gmail.com>
---
 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;
-- 
1.7.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-16 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2012-08-16  8:55   ` Jie Liu
2012-08-16 12:15     ` Wang Sheng-Hui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).