[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AE90C24D6B3A694183C094C60CF0A2F6026B73B9@saturn3.aculab.com>
Date: Mon, 28 Oct 2013 09:17:06 -0000
From: "David Laight" <David.Laight@...LAB.COM>
To: "Joe Perches" <joe@...ches.com>,
"Arvid Brodin" <arvid.brodin@...n.com>
Cc: <netdev@...r.kernel.org>, "David Miller" <davem@...emloft.net>,
"Stephen Hemminger" <shemminger@...tta.com>,
"Javier Boticario" <jboticario@...il.com>,
<balferreira@...glemail.com>,
Elías Molina Muñoz <elias.molina@....es>
Subject: RE: [PATCH v5] net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)
> 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.
Also, if these definitions are in a .h file they need better names
David
--
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