Skip to content

Commit 5f832a3

Browse files
damien-lemoalaxboe
authored andcommitted
scsi: sd_zbc: Fix sd_zbc_check_zones() error checks
The unsigned 32 bits overflow check for the zone size value is already done within sd_zbc_check_zones() with the test: } else if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) { so there is no need to check again for an out of range value in sd_zbc_read_zones(). Simplify the code and fix sd_zbc_check_zones() error return to -EFBIG instead of -ENODEV if the zone size is too large. Change the return type of sd_zbc_check_zones() to an int for the error code and return the zone size (zone_blocks) through a u32 pointer to avoid overflowing the signed 32 return value. Reviewed-by: Hannes Reinecke <hare@suse.com> Acked-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d2e428e commit 5f832a3

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/scsi/sd_zbc.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,15 @@ static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp,
373373
* Returns the zone size in number of blocks upon success or an error code
374374
* upon failure.
375375
*/
376-
static s64 sd_zbc_check_zones(struct scsi_disk *sdkp)
376+
static int sd_zbc_check_zones(struct scsi_disk *sdkp, u32 *zblocks)
377377
{
378378
u64 zone_blocks = 0;
379379
sector_t max_lba, block = 0;
380380
unsigned char *buf;
381381
unsigned char *rec;
382382
unsigned int buf_len;
383383
unsigned int list_length;
384-
s64 ret;
384+
int ret;
385385
u8 same;
386386

387387
/* Get a buffer */
@@ -472,9 +472,10 @@ static s64 sd_zbc_check_zones(struct scsi_disk *sdkp)
472472
if (sdkp->first_scan)
473473
sd_printk(KERN_NOTICE, sdkp,
474474
"Zone size too large\n");
475-
ret = -ENODEV;
475+
ret = -EFBIG;
476476
} else {
477-
ret = zone_blocks;
477+
*zblocks = zone_blocks;
478+
ret = 0;
478479
}
479480

480481
out_free:
@@ -668,7 +669,7 @@ static int sd_zbc_setup(struct scsi_disk *sdkp, u32 zone_blocks)
668669

669670
int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf)
670671
{
671-
int64_t zone_blocks;
672+
u32 zone_blocks;
672673
int ret;
673674

674675
if (!sd_is_zoned(sdkp))
@@ -687,12 +688,8 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf)
687688
* Check zone size: only devices with a constant zone size (except
688689
* an eventual last runt zone) that is a power of 2 are supported.
689690
*/
690-
zone_blocks = sd_zbc_check_zones(sdkp);
691-
ret = -EFBIG;
692-
if (zone_blocks != (u32)zone_blocks)
693-
goto err;
694-
ret = zone_blocks;
695-
if (ret < 0)
691+
ret = sd_zbc_check_zones(sdkp, &zone_blocks);
692+
if (ret != 0)
696693
goto err;
697694

698695
/* The drive satisfies the kernel restrictions: set it up */

0 commit comments

Comments
 (0)