All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arvid Brodin <arvid.brodin@xdin.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "Joe Perches" <joe@perches.com>,
	netdev@vger.kernel.org, "David Miller" <davem@davemloft.net>,
	"Stephen Hemminger" <shemminger@vyatta.com>,
	"Javier Boticario" <jboticario@gmail.com>,
	balferreira@googlemail.com,
	"Elías Molina Muñoz" <elias.molina@ehu.es>
Subject: Re: [PATCH v5] net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)
Date: Tue, 29 Oct 2013 21:36:59 +0100	[thread overview]
Message-ID: <52701C6B.6010900@xdin.com> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6026B73B9@saturn3.aculab.com>

On 2013-10-28 10:17, David Laight wrote:
>> Subject: Re: [PATCH v5] net/hsr: Add support for the High-availability Seamless Redundancy protocol
>> (HSRv0)
>>
>> On Fri, 2013-10-25 at 20:20 +0200, Arvid Brodin wrote:
>>> On 2013-10-23 18:52, Joe Perches wrote:
>>>> On Wed, 2013-10-23 at 18:09 +0200, Arvid Brodin wrote:
>> []
>>>>> +/* above(a, b) - return 1 if a > b, 0 otherwise.
>>>>> + */
>>>>> +static bool above(u16 a, u16 b)
>>>>> +{
>>>>> +	/* Remove inconsistency where above(a, b) == below(a, b) */
>>>>> +	if ((int) b - a == 32768)
>>>>> +		return 0;
>>>>> +
>>>>> +	return (((s16) (b - a)) < 0);
>>>>> +}
>>>>> +#define below(a, b)		above((b), (a))
>>>>> +#define above_or_eq(a, b)	(!below((a), (b)))
>>>>> +#define below_or_eq(a, b)	(!above((a), (b)))
>>>>
>>>> This looks odd.
>>>
>>> It relies on unsigned arithmetic to compare two values that may wrap. I.e.,
>>> it doesn't care about the absolute sizes, but only about the distance
>>> between the numbers.
> 
> I'd have thought it wasn't really worth worrying about what happens
> when a ^ b == 0x8000. Anything using modulo 16 distances shouldn't
> really see such values.
> Perhaps just document the effect.

Unfortunately there are circumstances where such values can be seen - 
specifically when there is a network problem. And since HSR is meant to
be a high-availability protocol, it is imperative that such cases are 
handled consistently. (That would have been the case with modulo 32 as
well, even if the occations when it happened would be a lot rarer, and
the resulting bugs would be much harder to find.)

> 
> Also, if these definitions are in a .h file they need better names

They're in a .c file, but between your's and Joe Perches' comments, I can
see that the names and description needs a face-lift.

Thanks for looking at the code!

> 
> 	David
> 

-- 
Arvid Brodin | Consultant (Linux)
XDIN AB | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden | xdin.com

      reply	other threads:[~2013-10-29 20:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-23 16:09 [PATCH v5] net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0) Arvid Brodin
2013-10-23 16:52 ` Joe Perches
2013-10-25 18:20   ` Arvid Brodin
2013-10-25 18:31     ` Joe Perches
2013-10-28  9:17       ` David Laight
2013-10-29 20:36         ` Arvid Brodin [this message]

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=52701C6B.6010900@xdin.com \
    --to=arvid.brodin@xdin.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=balferreira@googlemail.com \
    --cc=davem@davemloft.net \
    --cc=elias.molina@ehu.es \
    --cc=jboticario@gmail.com \
    --cc=joe@perches.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.