Re: [PATCH V4] hwmon: Add MCP3021 ADC driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 21 Feb 2012 09:52:09 +0000, Xie Xiaobo-R63061 wrote:
> > > +static inline u16 volts_from_reg(u16 vdd, u16 val) {
> > > +	if (val == 0)
> > > +		return 0;
> > > +
> > > +	val = val * MCP3021_OUTPUT_SCALE - MCP3021_OUTPUT_SCALE / 2;
> > > +
> > > +	return val * DIV_ROUND_CLOSEST(vdd,
> > > +			(1 << MCP3021_OUTPUT_RES) * MCP3021_OUTPUT_SCALE); }
> > 
> > I did not notice before, but can't this overflow? Say val == 0xfff0, 0xfff0 * 4 - 4 / 2
> > == 0x3ffbe, that doesn't fit in u16. I think you should introduce a local int variable
> > and return its value (as an int, not u16.)
> > 
> 
> I used the u16, because the val is from mcp3021_read16(), So the val always <= 0x3ff (I already defined MCP3021_SAR_MASK).

OK, you can ignore my comment then, sorry for the noise.

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@xxxxxxxxxxxxxx
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors


[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux