[PATCH v2] misc: i2c_eeprom: consider pagesize when writing to eeprom

Tom Rini trini at konsulko.com
Wed Oct 25 15:55:44 CEST 2023


On Wed, Oct 25, 2023 at 07:59:05AM +0000, Michel Alex wrote:

> Calculate the maximum length of the buffer when writing
> across the page boundary. If the buffer length (len)
> exceeds the page boundary (pagesize), split it. Use this
> length instead of comparing the length with the pagesize,
> because if the write start address (offset) is not at the
> beginning of a page and the page_offset + len is greater
> than the page boundary (pagesize), the write operation
> would overflow the current page and the behaviour can be
> undefined (e.g. at24).
> 
> Signed-off-by: Alex Michel <alex.michel at wiedemann-group.com>
[snip]
> +static int i2c_eeprom_len(unsigned int offset, unsigned int len, unsigned int pagesize)
[snip]
>  static int i2c_eeprom_std_write(struct udevice *dev, int offset,
>                                 const uint8_t *buf, int size)
>  {
> @@ -67,7 +78,7 @@ static int i2c_eeprom_std_write(struct udevice *dev, int offset,
>         int ret;
> 
>         while (size > 0) {
> -               int write_size = min_t(int, size, priv->pagesize);
> +               int write_size = i2c_eeprom_len(offset, size, priv->pagesize);
[snip]

We don't need to promote the types to unsigned here do we?

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20231025/9a15e302/attachment.sig>


More information about the U-Boot mailing list