From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiri Pirko Subject: Re: [patch net-next 2/2] team: avoid using variable-length array Date: Thu, 17 Nov 2011 16:10:32 +0100 Message-ID: <20111117151031.GA3209@minipsycho> References: <1321539365-1125-1-git-send-email-jpirko@redhat.com> <1321539365-1125-2-git-send-email-jpirko@redhat.com> <1321540278.2751.40.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE 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 To: Eric Dumazet Return-path: Received: from mx1.redhat.com ([209.132.183.28]:30126 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757774Ab1KQPKh (ORCPT ); Thu, 17 Nov 2011 10:10:37 -0500 Content-Disposition: inline In-Reply-To: <1321540278.2751.40.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> Sender: netdev-owner@vger.kernel.org List-ID: Thu, Nov 17, 2011 at 03:31:18PM CET, eric.dumazet@gmail.com wrote: >Le jeudi 17 novembre 2011 =E0 15:16 +0100, Jiri Pirko a =E9crit : >> Apparently using variable-length array is not correct >> (https://lkml.org/lkml/2011/10/23/25). So remove it. >>=20 >> Signed-off-by: Jiri Pirko >> --- >> drivers/net/team/team.c | 9 +++++++-- >> 1 files changed, 7 insertions(+), 2 deletions(-) >>=20 >> 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; >> =20 >> - memset(dst_opts, 0, sizeof(dst_opts)); >> + dst_opts =3D kzalloc(sizeof(struct team_option *) * option_count, >> + GFP_KERNEL); >> + if (!dst_opts) >> + return -ENOMEM; >> for (i =3D 0; i < option_count; i++, option++) { >> struct team_option *dst_opt; >> =20 >> @@ -119,12 +122,14 @@ int team_options_register(struct team *team, >> for (i =3D 0; i < option_count; i++) >> list_add_tail(&dst_opts[i]->list, &team->option_list); >> =20 >> + kfree(dst_opts); >> return 0; >> =20 >> rollback: >> for (i =3D 0; i < option_count; i++) >> kfree(dst_opts[i]); >> =20 >> + kfree(dst_opts); >> return err; >> } >> =20 > >Please use kmemdup() as well, or someone else will do it ;) > >dst_opt =3D kmalloc(sizeof(*option), GFP_KERNEL); >... >memcpy(dst_opt, option, sizeof(*option)); > >-> dst_opt =3D kmemdup(...); > Sure, I'll do this in separate patch. Thanks! Jirka