RE: [PATCH] bcd: limit bin2bcd input value to lie between 0-99

From: Venu Byravarasu
Date: Tue Nov 22 2011 - 22:52:17 EST


> >
> > e.g. say val passed to bin2bcd is 123.
> > In that case the expected value to be returned by
> > this function is 0x23.
> > However, without the fix being added, it would
> > return 0xC3.
> >
>
> I'm not sure that I agree. Passing 123 to bin2bcd() is a bug, isn't
> it? We want to know about bugs so we can fix them, and quietly repairing
> thngs in callees prevents that.

As bin2bcd is having "unsigned val" as parameter, I do not understand why passing 123 is a bug.
123 that I mentioned here in my example is a decimal value, which is very well within unsigned char limits.
Even any value beyond 99 would create this problem, as the values are not really getting stored as BCD, where each nibble value is to be limited to stay within 0 to 9.
Probably it would be better to change the param of "bin2bcd" from "unsigned val" to "unsigned char" itself.
--
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/