[i2c] [PATCH v3] rtc: RTC class driver for the ds1374

Scott Wood scottwood at freescale.com
Wed Aug 15 18:29:35 CEST 2007


Jean Delvare wrote:
> Hi Scott,
> 
> On Wed, 18 Jul 2007 17:28:18 -0500, Scott Wood wrote:
> 
>>This patch adds an RTC class driver for the Maxim/Dallas 1374 RTC chip,
>>based on drivers/i2c/chips/ds1374.c.  It supports alarm functionality.
>>
>>Signed-off-by: Scott Wood <scottwood at freescale.com>
> 
> 
> Looks good, just one thing:
> 
> 
>>+static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
>>+                           int reg, int nbytes)
>>+{
>>+	u8 buf[4];
>>+	int ret = i2c_smbus_read_i2c_block_data(client, reg, 4, buf);
> 
> 
> Shouldn't you read "nbytes" bytes here rather than hardcoding 4?

The buffer is only four bytes, so this causes an error to be returned 
rather than stack corruption if the caller tries to read more.  The 
overhead of reading four bytes when only three was requested (it's never 
called with fewer) is unlikely to be that significant.

-Scott



More information about the i2c mailing list