[PATCH 1/3] staging: comedi: comedi_bond: fix 'b_mask' calc in bonding_dio_insn_bits()

Dan Carpenter dan.carpenter at oracle.com
Tue Apr 21 20:09:10 UTC 2015


I knew the original was undefined because Ian showed me the relevant
section from the standard.  I'm actually surprised that it doesn't work
in GCC.  Using -fno-strict-overflow doesn't help either.  I think at the
optimizations that the kernel uses -O2 and -Os the original "works".

Anyway, the old code is definitely wrong.

But the new code is also undefined because we are subtracting from
INT_MIN.  I imagine how GCC could handle the undefined behavior in an
unexpected way so the new code is probably fine.  But we may as well
just be pedantic.

		b_mask = (b_chans < 32) ? ((1U << b_chans) - 1)
					: 0xffffffff;

regards,
dan carpenter



More information about the devel mailing list