diff options
-rw-r--r-- | drivers/scsi/sd.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index d8e2caf9f468..365024b0c407 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -1188,6 +1188,12 @@ static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) | |||
1188 | u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512); | 1188 | u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512); |
1189 | u64 bad_lba; | 1189 | u64 bad_lba; |
1190 | int info_valid; | 1190 | int info_valid; |
1191 | /* | ||
1192 | * resid is optional but mostly filled in. When it's unused, | ||
1193 | * its value is zero, so we assume the whole buffer transferred | ||
1194 | */ | ||
1195 | unsigned int transferred = scsi_bufflen(scmd) - scsi_get_resid(scmd); | ||
1196 | unsigned int good_bytes; | ||
1191 | 1197 | ||
1192 | if (scmd->request->cmd_type != REQ_TYPE_FS) | 1198 | if (scmd->request->cmd_type != REQ_TYPE_FS) |
1193 | return 0; | 1199 | return 0; |
@@ -1221,7 +1227,8 @@ static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) | |||
1221 | /* This computation should always be done in terms of | 1227 | /* This computation should always be done in terms of |
1222 | * the resolution of the device's medium. | 1228 | * the resolution of the device's medium. |
1223 | */ | 1229 | */ |
1224 | return (bad_lba - start_lba) * scmd->device->sector_size; | 1230 | good_bytes = (bad_lba - start_lba) * scmd->device->sector_size; |
1231 | return min(good_bytes, transferred); | ||
1225 | } | 1232 | } |
1226 | 1233 | ||
1227 | /** | 1234 | /** |