drivers/isl29020: fix return value integer error

Problem:

Since `i2c_read_reg` returns (signed) `int` values, the result can
be negative. However, the variable used to save the result is unsigned.

Fix:

Add and use a signed variable for return value storing.
dev/timer
Ludwig Ortmann 9 years ago
parent 8ba166df6d
commit a729afa9ec

@ -57,13 +57,14 @@ int isl29020_read(isl29020_t *dev)
{
char low, high;
uint16_t res;
int ret;
i2c_acquire(dev->i2c);
/* read lighting value */
res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
res += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
ret = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
ret += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
i2c_release(dev->i2c);
if (res < 2) {
if (ret < 2) {
return -1;
}
res = (high << 8) | low;

Loading…
Cancel
Save