Skip to content

cmd: mtd: fix default read behavior and boundary checks

Peter Suti u-boot 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 1 replyIn review
  2. v10 of 3 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Separate commit for additional debug logs for bad blocks.
- Return error when start_off >= mtd->size.
- Resent to fix threading issues from v1.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3cmd: mtd: add logs when bad blocks are encounteredcmd/mtd.c+4 -11 reply
2/3cmd: mtd: fix read failure on default full partition read with bad blockscmd/mtd.c+22 -00 replies
3/3cmd: mtd: fix default length calculation when offset is specifiedcmd/mtd.c+11 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] cmd: mtd: fix default read behavior and boundary checks

This series addresses two issues in the 'mtd read' command regarding how default read lengths are calculated and handled when no size argument is provided.

The first patch fixes a failure when reading a full NAND partition that contains bad blocks. Currently, skipping bad blocks increments the physical offset without adjusting the remaining byte count, causing the read to attempt accessing past the end of the partition. The fix ensures that default full-partition reads are truncated gracefully at the physical boundary rather than returning an error.
This behaviour is similar to the raw nand command which adjusts the size of the read with adjust_size_for_badblocks().

The second patch fixes the default length calculation when a starting offset is specified. Previously, the command defaulted to reading the entire partition size ('mtd->size') starting from the offset, which inevitably exceeds the partition bounds. The fix adjusts the default length to 'mtd->size - offset'.

Changes in v2:
- Separate commit for additional debug logs for bad blocks.
- Return error when start_off >= mtd->size.
- Resent to fix threading issues from v1.

Link to v1: https://lore.kernel.org/u-boot/[email protected]/T/#u

Peter Suti (3):
cmd: mtd: add logs when bad blocks are encountered
cmd: mtd: fix read failure on default full partition read with bad
blocks
cmd: mtd: fix default length calculation when offset is specified

 cmd/mtd.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0