scsi: sd_zbc: Fix sd_zbc_report_zones() buffer allocation
authorMasato Suzuki <masato.suzuki@wdc.com>
Thu, 14 Feb 2019 06:01:18 +0000 (15:01 +0900)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sat, 16 Feb 2019 03:09:54 +0000 (22:09 -0500)
commit515ce60613128be7a176a8b82b20c7624f3b440d
treeec4d61f77fde93eb7cf0a05aa307e4e9a7aaae46
parent79edd00dc6a96644d76b4a1cb97d94d49e026768
scsi: sd_zbc: Fix sd_zbc_report_zones() buffer allocation

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.

Fix this by limiting a report zone command buffer size to the minimum of
the device max_hw_sectors and calculated value based on the requested
number of zones. This does not change the semantic of the report_zones file
operation as report zones can always return less zone reports than
requested. Short reports are handled using a loop execution of the
report_zones file operation in the function blk_report_zones().

[Damien]
Before patch 'e76239a3748c ("block: add a report_zones method")', report
zones buffer allocation was limited to max_sectors when allocated in
blk_report_zones(). This however does not consider the actual format of the
device reply which is interface dependent.  Limiting the allocation based
on the size of the expected reply format rather than the size of the array
of generic sturct blkzone passed by blk_report_zones() makes more sense.

Fixes: e76239a3748c ("block: add a report_zones method")
Cc: stable@vger.kernel.org
Signed-off-by: Masato Suzuki <masato.suzuki@wdc.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/sd_zbc.c