Message ID | 20190214060118.15255-1-damien.lemoal@wdc.com (mailing list archive) |
---|---|
State | Mainlined |
Commit | 515ce60613128be7a176a8b82b20c7624f3b440d |
Headers | show |
Series | [v2] scsi: sd_zbc: Fix sd_zbc_report_zones() buffer allocation | expand |
Damien, > The function sd_zbc_do_report_zones() issues a REPORT ZONES command > with a buffer size calculated based on the number of zones requested > by the caller. This value should however not exceed the capabilities > of the hardware maximum command size, that is, should not exceed the > max_hw_sectors limit of the device. This problem leads to failures of > report zones commands when re-validating disks with some SAS HBAs. Applied to 5.0/scsi-fixes, thanks!
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index fff86940388b..a340af797a85 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -142,10 +142,12 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, return -EOPNOTSUPP; /* - * Get a reply buffer for the number of requested zones plus a header. - * For ATA, buffers must be aligned to 512B. + * Get a reply buffer for the number of requested zones plus a header, + * without exceeding the device maximum command size. For ATA disks, + * buffers must be aligned to 512B. */ - buflen = roundup((nrz + 1) * 64, 512); + buflen = min(queue_max_hw_sectors(disk->queue) << 9, + roundup((nrz + 1) * 64, 512)); buf = kmalloc(buflen, gfp_mask); if (!buf) return -ENOMEM;