Message ID | 1321539365-1125-2-git-send-email-jpirko@redhat.com |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
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
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
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
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
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 --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; }
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(-)