[i2c] [PATCH] rtc: RTC class driver for the ds1374
Scott Wood
scottwood at freescale.com
Fri Sep 28 17:34:30 CEST 2007
Andrew Morton wrote:
>> +static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
>> + int reg, int nbytes)
>> +{
>> + u8 buf[4];
>> + int ret;
>> + int i;
>> +
>> + if (nbytes > 4) {
>> + WARN_ON(1);
>> + return -EINVAL;
>> + }
>> +
>> + ret = i2c_smbus_read_i2c_block_data(client, reg, nbytes, buf);
>> +
>> + if (ret < 0)
>> + return ret;
>> + if (ret < nbytes)
>> + return -EIO;
>> +
>> + for (i = nbytes - 1, *time = 0; i >= 0; i--)
>> + *time = (*time << 8) | buf[i];
>> +
>> + return 0;
>> +}
>
> Are we sure that nbytes can never be negative here?
Yes, the only values that are passed in are 3 and 4. nbytes should
probably be unsigned just in case, though.
-Scott
More information about the i2c
mailing list