linux/drivers/misc/eeprom
Geert Uytterhoeven 19e506b317 eeprom: at25: Rework buggy read splitting
The recent change to split reads into chunks has several problems:
  1. If an SPI controller has no transfer size limit, max_chunk is
     SIZE_MAX, and num_msgs becomes zero, causing no data to be read
     into the buffer, and exposing the original contents of the buffer
     to userspace,
  2. If the requested read size is not a multiple of the maximum
     transfer size, the last transfer reads too much data, overflowing
     the buffer,
  3. The loop logic differs from the write case.

Fix the above by:
  1. Keeping track of the number of bytes that are still to be
     transferred, instead of precalculating the number of messages and
     keeping track of the number of bytes tranfered,
  2. Calculating the transfer size of each individual message, taking
     into account the number of bytes left,
  3. Switching from a "while"-loop to a "do-while"-loop, and renaming
     "msg_count" to "segment".

While at it, drop the superfluous cast from "unsigned int" to "unsigned
int", also from at25_ee_write(), where it was probably copied from.

Fixes: 0a35780c75 ("eeprom: at25: Split reads into chunks and cap write size")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/7ae260778d2c08986348ea48ce02ef148100e088.1655817534.git.geert+renesas@glider.be
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-06-27 16:21:05 +02:00
..
at24.c eeprom: at24: Add support for 24c1025 EEPROM 2021-12-13 14:42:39 +01:00
at25.c eeprom: at25: Rework buggy read splitting 2022-06-27 16:21:05 +02:00
digsy_mtc_eeprom.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ee1004.c eeprom: ee1004: limit i2c reads to I2C_SMBUS_BLOCK_MAX 2022-02-04 16:27:44 +01:00
eeprom_93cx6.c misc: eeprom: eeprom_93cx6: Repair function arg descriptions 2020-06-29 18:45:52 +02:00
eeprom_93xx46.c spi: make remove callback a void function 2022-02-09 13:00:45 +00:00
eeprom.c misc: eeprom: use helper to get i2c_client from kobj 2020-09-21 11:45:43 +02:00
idt_89hpesx.c eeprom: idt_89hpesx: use SPDX-License-Identifier 2021-06-09 18:39:40 +02:00
Kconfig nvmem: prepare basics for FRAM support 2021-06-11 12:23:10 +02:00
Makefile eeprom: New ee1004 driver for DDR4 memory 2018-10-15 20:51:46 +02:00
max6875.c misc: eeprom: max6875: convert to i2c_new_dummy_device 2019-07-25 10:06:54 +02:00