Skip to content

Commit d28d17a

Browse files
johnpgarrymartinkpetersen
authored andcommitted
scsi: scsi_debug: Fix do_device_access() handling of unexpected SG copy length
If the sg_copy_buffer() call returns less than sdebug_sector_size, then we drop out of the copy loop. However, we still report that we copied the full expected amount, which is not proper. Fix by keeping a running total and return that value. Fixes: 84f3a3c ("scsi: scsi_debug: Atomic write support") Reported-by: Colin Ian King <colin.i.king@gmail.com> Suggested-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: John Garry <john.g.garry@oracle.com> Link: https://lore.kernel.org/r/20241018101655.4207-1-john.g.garry@oracle.com Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Colin Ian King <colin.i.king@gmail.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent fca6cae commit d28d17a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/scsi/scsi_debug.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -3651,7 +3651,7 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
36513651
enum dma_data_direction dir;
36523652
struct scsi_data_buffer *sdb = &scp->sdb;
36533653
u8 *fsp;
3654-
int i;
3654+
int i, total = 0;
36553655

36563656
/*
36573657
* Even though reads are inherently atomic (in this driver), we expect
@@ -3688,18 +3688,16 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
36883688
fsp + (block * sdebug_sector_size),
36893689
sdebug_sector_size, sg_skip, do_write);
36903690
sdeb_data_sector_unlock(sip, do_write);
3691-
if (ret != sdebug_sector_size) {
3692-
ret += (i * sdebug_sector_size);
3691+
total += ret;
3692+
if (ret != sdebug_sector_size)
36933693
break;
3694-
}
36953694
sg_skip += sdebug_sector_size;
36963695
if (++block >= sdebug_store_sectors)
36973696
block = 0;
36983697
}
3699-
ret = num * sdebug_sector_size;
37003698
sdeb_data_unlock(sip, atomic);
37013699

3702-
return ret;
3700+
return total;
37033701
}
37043702

37053703
/* Returns number of bytes copied or -1 if error. */

0 commit comments

Comments
 (0)