Skip to content

Commit

Permalink
scsi: sd: sd_zbc: Verify that the zone size is a power of two
Browse files Browse the repository at this point in the history
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/[email protected]
Reviewed-by: Damien Le Moal <[email protected]>
Reviewed-by: Himanshu Madhani <[email protected]>
Acked-by: Douglas Gilbert <[email protected]>
Signed-off-by: Bart Van Assche <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
bvanassche authored and martinkpetersen committed Apr 26, 2022
1 parent aa96bfb commit 9a93b9c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/scsi/sd_zbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a93b9c

Please sign in to comment.