diff mbox

[net-next,2/2] team: avoid using variable-length array

Message ID 1321539365-1125-2-git-send-email-jpirko@redhat.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Jiri Pirko Nov. 17, 2011, 2:16 p.m. UTC
Apparently using variable-length array is not correct
(https://lkml.org/lkml/2011/10/23/25). So remove it.

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
---
 drivers/net/team/team.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

Comments

Eric Dumazet Nov. 17, 2011, 2:31 p.m. UTC | #1
Le jeudi 17 novembre 2011 à 15:16 +0100, Jiri Pirko a écrit :
> Apparently using variable-length array is not correct
> (https://lkml.org/lkml/2011/10/23/25). So remove it.
> 
> Signed-off-by: Jiri Pirko <jpirko@redhat.com>
> ---
>  drivers/net/team/team.c |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
> index 5b169c1..c48ef19 100644
> --- a/drivers/net/team/team.c
> +++ b/drivers/net/team/team.c
> @@ -96,10 +96,13 @@ int team_options_register(struct team *team,
>  			  size_t option_count)
>  {
>  	int i;
> -	struct team_option *dst_opts[option_count];
> +	struct team_option **dst_opts;
>  	int err;
>  
> -	memset(dst_opts, 0, sizeof(dst_opts));
> +	dst_opts = kzalloc(sizeof(struct team_option *) * option_count,
> +			   GFP_KERNEL);
> +	if (!dst_opts)
> +		return -ENOMEM;
>  	for (i = 0; i < option_count; i++, option++) {
>  		struct team_option *dst_opt;
>  
> @@ -119,12 +122,14 @@ int team_options_register(struct team *team,
>  	for (i = 0; i < option_count; i++)
>  		list_add_tail(&dst_opts[i]->list, &team->option_list);
>  
> +	kfree(dst_opts);
>  	return 0;
>  
>  rollback:
>  	for (i = 0; i < option_count; i++)
>  		kfree(dst_opts[i]);
>  
> +	kfree(dst_opts);
>  	return err;
>  }
>  

Please use kmemdup() as well, or someone else will do it ;)

dst_opt = kmalloc(sizeof(*option), GFP_KERNEL);
...
memcpy(dst_opt, option, sizeof(*option));

-> dst_opt = kmemdup(...);




--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Pirko Nov. 17, 2011, 3:10 p.m. UTC | #2
Thu, Nov 17, 2011 at 03:31:18PM CET, eric.dumazet@gmail.com wrote:
>Le jeudi 17 novembre 2011 à 15:16 +0100, Jiri Pirko a écrit :
>> Apparently using variable-length array is not correct
>> (https://lkml.org/lkml/2011/10/23/25). So remove it.
>> 
>> Signed-off-by: Jiri Pirko <jpirko@redhat.com>
>> ---
>>  drivers/net/team/team.c |    9 +++++++--
>>  1 files changed, 7 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
>> index 5b169c1..c48ef19 100644
>> --- a/drivers/net/team/team.c
>> +++ b/drivers/net/team/team.c
>> @@ -96,10 +96,13 @@ int team_options_register(struct team *team,
>>  			  size_t option_count)
>>  {
>>  	int i;
>> -	struct team_option *dst_opts[option_count];
>> +	struct team_option **dst_opts;
>>  	int err;
>>  
>> -	memset(dst_opts, 0, sizeof(dst_opts));
>> +	dst_opts = kzalloc(sizeof(struct team_option *) * option_count,
>> +			   GFP_KERNEL);
>> +	if (!dst_opts)
>> +		return -ENOMEM;
>>  	for (i = 0; i < option_count; i++, option++) {
>>  		struct team_option *dst_opt;
>>  
>> @@ -119,12 +122,14 @@ int team_options_register(struct team *team,
>>  	for (i = 0; i < option_count; i++)
>>  		list_add_tail(&dst_opts[i]->list, &team->option_list);
>>  
>> +	kfree(dst_opts);
>>  	return 0;
>>  
>>  rollback:
>>  	for (i = 0; i < option_count; i++)
>>  		kfree(dst_opts[i]);
>>  
>> +	kfree(dst_opts);
>>  	return err;
>>  }
>>  
>
>Please use kmemdup() as well, or someone else will do it ;)
>
>dst_opt = kmalloc(sizeof(*option), GFP_KERNEL);
>...
>memcpy(dst_opt, option, sizeof(*option));
>
>-> dst_opt = kmemdup(...);
>
Sure, I'll do this in separate patch.

Thanks!

Jirka
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Nov. 17, 2011, 6:40 p.m. UTC | #3
From: Jiri Pirko <jpirko@redhat.com>
Date: Thu, 17 Nov 2011 16:10:32 +0100

> Sure, I'll do this in separate patch.

No, you'll do it in _this_ patch.

Jiri, please stop resisting the incorporation of feedback into
the patches you post.  You've done this twice in the past 3 days
and it's really irritating.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Pirko Nov. 17, 2011, 6:52 p.m. UTC | #4
Thu, Nov 17, 2011 at 07:40:22PM CET, davem@davemloft.net wrote:
>From: Jiri Pirko <jpirko@redhat.com>
>Date: Thu, 17 Nov 2011 16:10:32 +0100
>
>> Sure, I'll do this in separate patch.
>
>No, you'll do it in _this_ patch.
>
>Jiri, please stop resisting the incorporation of feedback into
>the patches you post.  You've done this twice in the past 3 days
>and it's really irritating.

Well, the change Eric suggested is unrelated to this patch so it seemed
good to me to do not mangle it together.

Anyway, I'm sorry being source of irritation :( (alhought I have
absolutelly no intention to do so)

Jirka
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Nov. 18, 2011, 8 p.m. UTC | #5
From: Jiri Pirko <jpirko@redhat.com>
Date: Thu, 17 Nov 2011 15:16:05 +0100

> Apparently using variable-length array is not correct
> (https://lkml.org/lkml/2011/10/23/25). So remove it.
> 
> Signed-off-by: Jiri Pirko <jpirko@redhat.com>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 5b169c1..c48ef19 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -96,10 +96,13 @@  int team_options_register(struct team *team,
 			  size_t option_count)
 {
 	int i;
-	struct team_option *dst_opts[option_count];
+	struct team_option **dst_opts;
 	int err;
 
-	memset(dst_opts, 0, sizeof(dst_opts));
+	dst_opts = kzalloc(sizeof(struct team_option *) * option_count,
+			   GFP_KERNEL);
+	if (!dst_opts)
+		return -ENOMEM;
 	for (i = 0; i < option_count; i++, option++) {
 		struct team_option *dst_opt;
 
@@ -119,12 +122,14 @@  int team_options_register(struct team *team,
 	for (i = 0; i < option_count; i++)
 		list_add_tail(&dst_opts[i]->list, &team->option_list);
 
+	kfree(dst_opts);
 	return 0;
 
 rollback:
 	for (i = 0; i < option_count; i++)
 		kfree(dst_opts[i]);
 
+	kfree(dst_opts);
 	return err;
 }