netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jpirko@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	bhutchings@solarflare.com, shemminger@vyatta.com,
	andy@greyhouse.net, fbl@redhat.com, jzupka@redhat.com,
	ivecera@redhat.com, mirqus@gmail.com
Subject: Re: [patch net-next 2/2] team: avoid using variable-length array
Date: Thu, 17 Nov 2011 16:10:32 +0100	[thread overview]
Message-ID: <20111117151031.GA3209@minipsycho> (raw)
In-Reply-To: <1321540278.2751.40.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>

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

  reply	other threads:[~2011-11-17 15:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17 14:16 [patch net-next 1/2] team: add fix_features Jiri Pirko
2011-11-17 14:16 ` [patch net-next 2/2] team: avoid using variable-length array Jiri Pirko
2011-11-17 14:31   ` Eric Dumazet
2011-11-17 15:10     ` Jiri Pirko [this message]
2011-11-17 18:40       ` David Miller
2011-11-17 18:52         ` Jiri Pirko
2011-11-18 20:00   ` David Miller
2011-11-17 20:28 ` [patch net-next 1/2] team: add fix_features Michał Mirosław
2011-11-18 20:00 ` David Miller

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=20111117151031.GA3209@minipsycho \
    --to=jpirko@redhat.com \
    --cc=andy@greyhouse.net \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=fbl@redhat.com \
    --cc=ivecera@redhat.com \
    --cc=jzupka@redhat.com \
    --cc=mirqus@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.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 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).