* [PATCH] bonding: cleanup bond_opts array
@ 2015-01-09 18:31 Jonathan Toppins
2015-01-09 18:48 ` Andy Gospodarek
2015-01-12 21:43 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Toppins @ 2015-01-09 18:31 UTC (permalink / raw)
To: netdev; +Cc: shm, Andy Gospodarek, Nikolay Aleksandrov
Remove the empty array element initializer and size the array with
BOND_OPT_LAST so the compiler will complain if more elements are in
there than should be.
An interesting unwanted side effect of this initializer is that if one
inserts new options into the middle of the array then this initializer
will zero out the option that equals BOND_OPT_TLB_DYNAMIC_LB+1.
Example:
Extend the OPTS enum:
enum {
...
BOND_OPT_TLB_DYNAMIC_LB,
BOND_OPT_LACP_NEW1,
BOND_OPT_LAST
};
Now insert into bond_opts array:
static const struct bond_option bond_opts[] = {
...
[BOND_OPT_LACP_RATE] = { .... unchanged stuff .... },
[BOND_OPT_LACP_NEW1] = { ... new stuff ... },
...
[BOND_OPT_TLB_DYNAMIC_LB] = { .... unchanged stuff ....},
{ } // MARK A
};
Since BOND_OPT_LACP_NEW1 = BOND_OPT_TLB_DYNAMIC_LB+1, the last
initializer (MARK A) will overwrite the contents of BOND_OPT_LACP_NEW1
and can be easily viewed with the crash utility.
Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Cc: Andy Gospodarek <gospo@cumulusnetworks.com>
Cc: Nikolay Aleksandrov <nikolay@redhat.com>
---
drivers/net/bonding/bond_options.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 1a61cc9..9bd538d4 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -186,7 +186,7 @@ static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = {
{ NULL, -1, 0}
};
-static const struct bond_option bond_opts[] = {
+static const struct bond_option bond_opts[BOND_OPT_LAST] = {
[BOND_OPT_MODE] = {
.id = BOND_OPT_MODE,
.name = "mode",
@@ -379,8 +379,7 @@ static const struct bond_option bond_opts[] = {
.values = bond_tlb_dynamic_lb_tbl,
.flags = BOND_OPTFLAG_IFDOWN,
.set = bond_option_tlb_dynamic_lb_set,
- },
- { }
+ }
};
/* Searches for an option by name */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] bonding: cleanup bond_opts array
2015-01-09 18:31 [PATCH] bonding: cleanup bond_opts array Jonathan Toppins
@ 2015-01-09 18:48 ` Andy Gospodarek
2015-01-12 11:05 ` Nikolay Aleksandrov
2015-01-12 21:43 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Andy Gospodarek @ 2015-01-09 18:48 UTC (permalink / raw)
To: Jonathan Toppins; +Cc: netdev, shm, Nikolay Aleksandrov
On Fri, Jan 09, 2015 at 01:31:08PM -0500, Jonathan Toppins wrote:
> Remove the empty array element initializer and size the array with
> BOND_OPT_LAST so the compiler will complain if more elements are in
> there than should be.
>
> An interesting unwanted side effect of this initializer is that if one
> inserts new options into the middle of the array then this initializer
> will zero out the option that equals BOND_OPT_TLB_DYNAMIC_LB+1.
>
> Example:
> Extend the OPTS enum:
> enum {
> ...
> BOND_OPT_TLB_DYNAMIC_LB,
> BOND_OPT_LACP_NEW1,
> BOND_OPT_LAST
> };
>
> Now insert into bond_opts array:
> static const struct bond_option bond_opts[] = {
> ...
> [BOND_OPT_LACP_RATE] = { .... unchanged stuff .... },
> [BOND_OPT_LACP_NEW1] = { ... new stuff ... },
> ...
> [BOND_OPT_TLB_DYNAMIC_LB] = { .... unchanged stuff ....},
> { } // MARK A
> };
>
> Since BOND_OPT_LACP_NEW1 = BOND_OPT_TLB_DYNAMIC_LB+1, the last
> initializer (MARK A) will overwrite the contents of BOND_OPT_LACP_NEW1
> and can be easily viewed with the crash utility.
>
> Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
> Cc: Andy Gospodarek <gospo@cumulusnetworks.com>
> Cc: Nikolay Aleksandrov <nikolay@redhat.com>
I do not recall if there was a specific reason that Nik added this, so
presuming there was not....
Signed-off-by: Andy Gospodarek <gospo@cumulusnetworks.com>
> ---
> drivers/net/bonding/bond_options.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
> index 1a61cc9..9bd538d4 100644
> --- a/drivers/net/bonding/bond_options.c
> +++ b/drivers/net/bonding/bond_options.c
> @@ -186,7 +186,7 @@ static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = {
> { NULL, -1, 0}
> };
>
> -static const struct bond_option bond_opts[] = {
> +static const struct bond_option bond_opts[BOND_OPT_LAST] = {
> [BOND_OPT_MODE] = {
> .id = BOND_OPT_MODE,
> .name = "mode",
> @@ -379,8 +379,7 @@ static const struct bond_option bond_opts[] = {
> .values = bond_tlb_dynamic_lb_tbl,
> .flags = BOND_OPTFLAG_IFDOWN,
> .set = bond_option_tlb_dynamic_lb_set,
> - },
> - { }
> + }
> };
>
> /* Searches for an option by name */
> --
> 1.7.10.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] bonding: cleanup bond_opts array
2015-01-09 18:48 ` Andy Gospodarek
@ 2015-01-12 11:05 ` Nikolay Aleksandrov
0 siblings, 0 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2015-01-12 11:05 UTC (permalink / raw)
To: Andy Gospodarek, Jonathan Toppins; +Cc: netdev, shm
On 09/01/15 19:48, Andy Gospodarek wrote:
> On Fri, Jan 09, 2015 at 01:31:08PM -0500, Jonathan Toppins wrote:
>> Remove the empty array element initializer and size the array with
>> BOND_OPT_LAST so the compiler will complain if more elements are in
>> there than should be.
>>
>> An interesting unwanted side effect of this initializer is that if one
>> inserts new options into the middle of the array then this initializer
>> will zero out the option that equals BOND_OPT_TLB_DYNAMIC_LB+1.
>>
>> Example:
>> Extend the OPTS enum:
>> enum {
>> ...
>> BOND_OPT_TLB_DYNAMIC_LB,
>> BOND_OPT_LACP_NEW1,
>> BOND_OPT_LAST
>> };
>>
>> Now insert into bond_opts array:
>> static const struct bond_option bond_opts[] = {
>> ...
>> [BOND_OPT_LACP_RATE] = { .... unchanged stuff .... },
>> [BOND_OPT_LACP_NEW1] = { ... new stuff ... },
>> ...
>> [BOND_OPT_TLB_DYNAMIC_LB] = { .... unchanged stuff ....},
>> { } // MARK A
>> };
>>
>> Since BOND_OPT_LACP_NEW1 = BOND_OPT_TLB_DYNAMIC_LB+1, the last
>> initializer (MARK A) will overwrite the contents of BOND_OPT_LACP_NEW1
>> and can be easily viewed with the crash utility.
>>
>> Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
>> Cc: Andy Gospodarek <gospo@cumulusnetworks.com>
>> Cc: Nikolay Aleksandrov <nikolay@redhat.com>
>
> I do not recall if there was a specific reason that Nik added this, so
> presuming there was not....
>
> Signed-off-by: Andy Gospodarek <gospo@cumulusnetworks.com>
>
Indeed, it's an oversight on my part from a previous version of the opts
patch-set which used a different end-of-array indicator :-)
Acked-by: Nikolay Aleksandrov <nikolay@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] bonding: cleanup bond_opts array
2015-01-09 18:31 [PATCH] bonding: cleanup bond_opts array Jonathan Toppins
2015-01-09 18:48 ` Andy Gospodarek
@ 2015-01-12 21:43 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-01-12 21:43 UTC (permalink / raw)
To: jtoppins; +Cc: netdev, shm, gospo, nikolay
From: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Date: Fri, 9 Jan 2015 13:31:08 -0500
> Remove the empty array element initializer and size the array with
> BOND_OPT_LAST so the compiler will complain if more elements are in
> there than should be.
>
> An interesting unwanted side effect of this initializer is that if one
> inserts new options into the middle of the array then this initializer
> will zero out the option that equals BOND_OPT_TLB_DYNAMIC_LB+1.
>
> Example:
> Extend the OPTS enum:
> enum {
> ...
> BOND_OPT_TLB_DYNAMIC_LB,
> BOND_OPT_LACP_NEW1,
> BOND_OPT_LAST
> };
>
> Now insert into bond_opts array:
> static const struct bond_option bond_opts[] = {
> ...
> [BOND_OPT_LACP_RATE] = { .... unchanged stuff .... },
> [BOND_OPT_LACP_NEW1] = { ... new stuff ... },
> ...
> [BOND_OPT_TLB_DYNAMIC_LB] = { .... unchanged stuff ....},
> { } // MARK A
> };
>
> Since BOND_OPT_LACP_NEW1 = BOND_OPT_TLB_DYNAMIC_LB+1, the last
> initializer (MARK A) will overwrite the contents of BOND_OPT_LACP_NEW1
> and can be easily viewed with the crash utility.
>
> Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-01-12 21:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09 18:31 [PATCH] bonding: cleanup bond_opts array Jonathan Toppins
2015-01-09 18:48 ` Andy Gospodarek
2015-01-12 11:05 ` Nikolay Aleksandrov
2015-01-12 21:43 ` David Miller
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).