
From: Simon Glass <sjg@chromium.org> The current code never returns an error if something goes wrong. While it is normally useful to return the number of blocks processed, when nothing is read/written at all, there is clearly something wrong. Update the logic to return -EIO in this case. Avoid changing blkcnt since it is an input parameter and this is confusing. Signed-off-by: Simon Glass <sjg@chromium.org> --- drivers/scsi/scsi.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index b32eb1be2b3..a1612a4f4c0 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -185,14 +185,18 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, start, smallblks, buf_addr); if (scsi_exec(bdev, pccb)) { scsi_print_error(pccb); - blkcnt -= blks; break; } buf_addr += pccb->datalen; - } while (blks != 0); + } while (blks); debug("scsi_read_ext: end startblk " LBAF ", blccnt %x buffer %lX\n", start, smallblks, buf_addr); - return blkcnt; + + /* Report an I/O error if nothing was read */ + if (blks == blkcnt) + return -EIO; + + return blkcnt - blks; } /******************************************************************************* @@ -243,14 +247,18 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, __func__, start, smallblks, buf_addr); if (scsi_exec(bdev, pccb)) { scsi_print_error(pccb); - blkcnt -= blks; break; } buf_addr += pccb->datalen; - } while (blks != 0); + } while (blks); debug("%s: end startblk " LBAF ", blccnt %x buffer %lX\n", __func__, start, smallblks, buf_addr); - return blkcnt; + + /* Report an I/O error if nothing was written */ + if (blks == blkcnt) + return -EIO; + + return blkcnt - blks; } #if IS_ENABLED(CONFIG_BOUNCE_BUFFER) -- 2.43.0