netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Veaceslav Falico <vfalico@redhat.com>
To: Nikolay Aleksandrov <nikolay@redhat.com>
Cc: netdev@vger.kernel.org, Andy Gospodarek <andy@greyhouse.net>,
	Jay Vosburgh <fubar@us.ibm.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net] bonding: fix packets_per_slave showing
Date: Thu, 5 Dec 2013 12:08:43 +0100	[thread overview]
Message-ID: <20131205110843.GD23210@redhat.com> (raw)
In-Reply-To: <1386239818-7408-1-git-send-email-nikolay@redhat.com>

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@redhat.com>

>
>CC: Andy Gospodarek <andy@greyhouse.net>
>CC: Jay Vosburgh <fubar@us.ibm.com>
>CC: Veaceslav Falico <vfalico@redhat.com>
>CC: David S. Miller <davem@davemloft.net>
>Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.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
>

  reply	other threads:[~2013-12-05 11:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05 10:36 [PATCH net] bonding: fix packets_per_slave showing Nikolay Aleksandrov
2013-12-05 11:08 ` Veaceslav Falico [this message]
2013-12-05 11:35   ` Nikolay Aleksandrov
2013-12-05 12:33   ` Eric Dumazet
2013-12-05 12:42     ` Nikolay Aleksandrov
2013-12-05 12:42     ` Veaceslav Falico
2013-12-05 13:03       ` Eric Dumazet
2013-12-06 20:17 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131205110843.GD23210@redhat.com \
    --to=vfalico@redhat.com \
    --cc=andy@greyhouse.net \
    --cc=davem@davemloft.net \
    --cc=fubar@us.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).