aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sd_zbc.c
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2022-04-21 11:30:16 -0700
committerMartin K. Petersen <martin.petersen@oracle.com>2022-04-25 23:23:04 -0400
commit9a93b9c9d38aee1f729f3cea72971a2616dca936 (patch)
tree50462096621bf891cdf3dc6136696ed1172de8c0 /drivers/scsi/sd_zbc.c
parentscsi: sd: sd_zbc: Improve source code documentation (diff)
downloadlinux-dev-9a93b9c9d38aee1f729f3cea72971a2616dca936.tar.xz
linux-dev-9a93b9c9d38aee1f729f3cea72971a2616dca936.zip
scsi: sd: sd_zbc: Verify that the zone size is a power of two
The following check in sd_zbc_cmnd_checks() can only work correctly if the zone size is a power of two: if (sector & (sd_zbc_zone_sectors(sdkp) - 1)) /* Unaligned request */ return BLK_STS_IOERR; Hence this patch that verifies that the zone size is a power of two. Link: https://lore.kernel.org/r/20220421183023.3462291-3-bvanassche@acm.org Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Acked-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi/sd_zbc.c')
-rw-r--r--drivers/scsi/sd_zbc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 2ae44bc52a5f..9ef5ad345185 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -664,6 +664,13 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
return -EFBIG;
}
+ if (!is_power_of_2(zone_blocks)) {
+ sd_printk(KERN_ERR, sdkp,
+ "Zone size %llu is not a power of two.\n",
+ zone_blocks);
+ return -EINVAL;
+ }
+
*zblocks = zone_blocks;
return 0;