Skip to content

Commit 6780414

Browse files
Fam Zhengmartinkpetersen
authored andcommitted
scsi: sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable
If device reports a small max_xfer_blocks and a zero opt_xfer_blocks, we end up using BLK_DEF_MAX_SECTORS, which is wrong and r/w of that size may get error. [mkp: tweaked to avoid setting rw_max twice and added typecast] Cc: <[email protected]> # v4.4+ Fixes: ca369d5 ("block/sd: Fix device-imposed transfer length limits") Signed-off-by: Fam Zheng <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent a3902ee commit 6780414

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/sd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
29562956
q->limits.io_opt = logical_to_bytes(sdp, sdkp->opt_xfer_blocks);
29572957
rw_max = logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
29582958
} else
2959-
rw_max = BLK_DEF_MAX_SECTORS;
2959+
rw_max = min_not_zero(logical_to_sectors(sdp, dev_max),
2960+
(sector_t)BLK_DEF_MAX_SECTORS);
29602961

29612962
/* Combine with controller limits */
29622963
q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q));

0 commit comments

Comments
 (0)