[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1321540278.2751.40.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>
Date: Thu, 17 Nov 2011 15:31:18 +0100
From: Eric Dumazet <eric.dumazet@...il.com>
To: Jiri Pirko <jpirko@...hat.com>
Cc: netdev@...r.kernel.org, davem@...emloft.net,
bhutchings@...arflare.com, shemminger@...tta.com,
andy@...yhouse.net, fbl@...hat.com, jzupka@...hat.com,
ivecera@...hat.com, mirqus@...il.com
Subject: Re: [patch net-next 2/2] team: avoid using variable-length array
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@...hat.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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists