From bbac37faadf2ee9752bd2b8ad69d62cb372b1e6f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 13 Jan 2023 11:32:06 -0800 Subject: [PATCH] ANDROID: scsi: sd_zbc: Work around non-compliance ZBC requires that every LBA is associated with a zone. Some zoned devices do not associate a zone with the last LBA. Let the kernel use these devices instead of rejecting them as follows: sd 0:0:0:4: [sde] 59552768 4096-byte logical blocks: (244 GB/227 GiB) sde: detected capacity change from 0 to 476422144 sd 0:0:0:4: [sde] REPORT ZONES report invalid length 0 sde: failed to revalidate zones sde: detected capacity change from 476422144 to 0 This patch will be reverted after the firmware bug has been fixed. Bug: 258289823 Change-Id: Ic7f13d1742bdd144fd4df2d37a3ed3dd93e65a2e Signed-off-by: Bart Van Assche --- drivers/scsi/sd_zbc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 164f41fcf9eb..068a3832b5f5 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -274,6 +274,17 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, while (zone_idx < nr_zones && lba < sdkp->capacity) { ret = sd_zbc_do_report_zones(sdkp, buf, buflen, lba, true); + if (ret && zone_idx) { + sd_printk(KERN_WARNING, sdkp, + "ZBC violation: %llu LBAs are not associated with a zone (zone length %llu)\n", + sdkp->capacity - lba, zone_length); + sdkp->capacity = lba; + set_capacity_and_notify(disk, + logical_to_sectors(sdkp->device, + sdkp->capacity)); + ret = 0; + break; + } if (ret) goto out;