Re: [RFC] change non-atomic bitops method

From: Uwe Kleine-König
Date: Tue Feb 03 2015 - 14:11:01 EST


Hello,

[added some more context again]

On Tue, Feb 03, 2015 at 03:14:43PM +0000, David Howells wrote:
> > > - *p |= mask;
> > > + if ((*p & mask) == 0)
> > > + *p |= mask;
> > Care to fix the double space here while touching the code?
> >
> > I think the more natural check here is:
> >
> > if ((~*p & mask) != 0)
> > *p |= mask;
> >
> > Might be a matter of taste, but this check is equivalent to
> >
> > *p != (*p | mask)
> >
> > which is what you really want to test for.
> I would argue that this is less clear as to what's going on.
OK, I admit that this equivalence is not obvious. Then maybe let the
compiler find the equivalence and do:

- *p |= mask;
+ if (*p != (*p | mask))
+ p |= mask;

?

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/