[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20131205110843.GD23210@redhat.com>
Date: Thu, 5 Dec 2013 12:08:43 +0100
From: Veaceslav Falico <vfalico@...hat.com>
To: Nikolay Aleksandrov <nikolay@...hat.com>
Cc: netdev@...r.kernel.org, Andy Gospodarek <andy@...yhouse.net>,
Jay Vosburgh <fubar@...ibm.com>,
"David S. Miller" <davem@...emloft.net>
Subject: Re: [PATCH net] bonding: fix packets_per_slave showing
On Thu, Dec 05, 2013 at 11:36:58AM +0100, Nikolay Aleksandrov wrote:
>There's an issue when showing the value of packets_per_slave due to
>using signed integer. The value may be < 0 and thus not put through
>reciprocal_value() before showing. This patch makes it use unsigned
>integer when showing it.
I was already checking my basic algebra knowledge here,
reciprocal_value(reciprocal_value(0..USHRT_MAX)) can become negative?!? :)
If anyone's also wondering...
packets_per_slave is reciprocal_value(0..USHRT_MAX), and thus can indeed be
negative, and then the code
if (packets_per_slave > 1)
packets_per_slave = reciprocal_value(packets_per_slave);
would fail to recognise that it's a reciprocal_divide() value, and not a
standard 0/1 option (in bond_rr_gen_slave_id() we verify it via a switch,
so we're safe there) - and thus output nonsense.
Acked-by: Veaceslav Falico <vfalico@...hat.com>
>
>CC: Andy Gospodarek <andy@...yhouse.net>
>CC: Jay Vosburgh <fubar@...ibm.com>
>CC: Veaceslav Falico <vfalico@...hat.com>
>CC: David S. Miller <davem@...emloft.net>
>Signed-off-by: Nikolay Aleksandrov <nikolay@...hat.com>
>---
> drivers/net/bonding/bond_sysfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
>index abf5e10..0ae580b 100644
>--- a/drivers/net/bonding/bond_sysfs.c
>+++ b/drivers/net/bonding/bond_sysfs.c
>@@ -1635,12 +1635,12 @@ static ssize_t bonding_show_packets_per_slave(struct device *d,
> char *buf)
> {
> struct bonding *bond = to_bond(d);
>- int packets_per_slave = bond->params.packets_per_slave;
>+ unsigned int packets_per_slave = bond->params.packets_per_slave;
>
> if (packets_per_slave > 1)
> packets_per_slave = reciprocal_value(packets_per_slave);
>
>- return sprintf(buf, "%d\n", packets_per_slave);
>+ return sprintf(buf, "%u\n", packets_per_slave);
> }
>
> static ssize_t bonding_store_packets_per_slave(struct device *d,
>--
>1.8.1.4
>
--
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