aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/sd_zbc.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 27793b9f54c0..9049a189c8e5 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -486,7 +486,7 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf)
486 */ 486 */
487static int sd_zbc_check_zone_size(struct scsi_disk *sdkp) 487static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
488{ 488{
489 u64 zone_blocks; 489 u64 zone_blocks = 0;
490 sector_t block = 0; 490 sector_t block = 0;
491 unsigned char *buf; 491 unsigned char *buf;
492 unsigned char *rec; 492 unsigned char *rec;
@@ -504,10 +504,8 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
504 504
505 /* Do a report zone to get the same field */ 505 /* Do a report zone to get the same field */
506 ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0); 506 ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0);
507 if (ret) { 507 if (ret)
508 zone_blocks = 0; 508 goto out_free;
509 goto out;
510 }
511 509
512 same = buf[4] & 0x0f; 510 same = buf[4] & 0x0f;
513 if (same > 0) { 511 if (same > 0) {
@@ -547,7 +545,7 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
547 ret = sd_zbc_report_zones(sdkp, buf, 545 ret = sd_zbc_report_zones(sdkp, buf,
548 SD_ZBC_BUF_SIZE, block); 546 SD_ZBC_BUF_SIZE, block);
549 if (ret) 547 if (ret)
550 return ret; 548 goto out_free;
551 } 549 }
552 550
553 } while (block < sdkp->capacity); 551 } while (block < sdkp->capacity);
@@ -555,35 +553,32 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
555 zone_blocks = sdkp->zone_blocks; 553 zone_blocks = sdkp->zone_blocks;
556 554
557out: 555out:
558 kfree(buf);
559
560 if (!zone_blocks) { 556 if (!zone_blocks) {
561 if (sdkp->first_scan) 557 if (sdkp->first_scan)
562 sd_printk(KERN_NOTICE, sdkp, 558 sd_printk(KERN_NOTICE, sdkp,
563 "Devices with non constant zone " 559 "Devices with non constant zone "
564 "size are not supported\n"); 560 "size are not supported\n");
565 return -ENODEV; 561 ret = -ENODEV;
566 } 562 } else if (!is_power_of_2(zone_blocks)) {
567
568 if (!is_power_of_2(zone_blocks)) {
569 if (sdkp->first_scan) 563 if (sdkp->first_scan)
570 sd_printk(KERN_NOTICE, sdkp, 564 sd_printk(KERN_NOTICE, sdkp,
571 "Devices with non power of 2 zone " 565 "Devices with non power of 2 zone "
572 "size are not supported\n"); 566 "size are not supported\n");
573 return -ENODEV; 567 ret = -ENODEV;
574 } 568 } else if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
575
576 if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
577 if (sdkp->first_scan) 569 if (sdkp->first_scan)
578 sd_printk(KERN_NOTICE, sdkp, 570 sd_printk(KERN_NOTICE, sdkp,
579 "Zone size too large\n"); 571 "Zone size too large\n");
580 return -ENODEV; 572 ret = -ENODEV;
573 } else {
574 sdkp->zone_blocks = zone_blocks;
575 sdkp->zone_shift = ilog2(zone_blocks);
581 } 576 }
582 577
583 sdkp->zone_blocks = zone_blocks; 578out_free:
584 sdkp->zone_shift = ilog2(zone_blocks); 579 kfree(buf);
585 580
586 return 0; 581 return ret;
587} 582}
588 583
589static int sd_zbc_setup(struct scsi_disk *sdkp) 584static int sd_zbc_setup(struct scsi_disk *sdkp)