@@ -111,7 +111,7 @@ static struct lock_class_key sr_bio_compl_lkclass;
111111static int sr_open (struct cdrom_device_info * , int );
112112static void sr_release (struct cdrom_device_info * );
113113
114- static void get_sectorsize (struct scsi_cd * );
114+ static int get_sectorsize (struct scsi_cd * );
115115static int get_capabilities (struct scsi_cd * );
116116
117117static unsigned int sr_check_events (struct cdrom_device_info * cdi ,
@@ -473,15 +473,15 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt)
473473 return BLK_STS_IOERR ;
474474}
475475
476- static void sr_revalidate_disk (struct scsi_cd * cd )
476+ static int sr_revalidate_disk (struct scsi_cd * cd )
477477{
478478 struct scsi_sense_hdr sshdr ;
479479
480480 /* if the unit is not ready, nothing more to do */
481481 if (scsi_test_unit_ready (cd -> device , SR_TIMEOUT , MAX_RETRIES , & sshdr ))
482- return ;
482+ return 0 ;
483483 sr_cd_check (& cd -> cdi );
484- get_sectorsize (cd );
484+ return get_sectorsize (cd );
485485}
486486
487487static int sr_block_open (struct gendisk * disk , blk_mode_t mode )
@@ -494,13 +494,16 @@ static int sr_block_open(struct gendisk *disk, blk_mode_t mode)
494494 return - ENXIO ;
495495
496496 scsi_autopm_get_device (sdev );
497- if (disk_check_media_change (disk ))
498- sr_revalidate_disk (cd );
497+ if (disk_check_media_change (disk )) {
498+ ret = sr_revalidate_disk (cd );
499+ if (ret )
500+ goto out ;
501+ }
499502
500503 mutex_lock (& cd -> lock );
501504 ret = cdrom_open (& cd -> cdi , mode );
502505 mutex_unlock (& cd -> lock );
503-
506+ out :
504507 scsi_autopm_put_device (sdev );
505508 if (ret )
506509 scsi_device_put (cd -> device );
@@ -685,7 +688,9 @@ static int sr_probe(struct device *dev)
685688 blk_pm_runtime_init (sdev -> request_queue , dev );
686689
687690 dev_set_drvdata (dev , cd );
688- sr_revalidate_disk (cd );
691+ error = sr_revalidate_disk (cd );
692+ if (error )
693+ goto unregister_cdrom ;
689694
690695 error = device_add_disk (& sdev -> sdev_gendev , disk , NULL );
691696 if (error )
@@ -714,13 +719,14 @@ static int sr_probe(struct device *dev)
714719}
715720
716721
717- static void get_sectorsize (struct scsi_cd * cd )
722+ static int get_sectorsize (struct scsi_cd * cd )
718723{
724+ struct request_queue * q = cd -> device -> request_queue ;
719725 static const u8 cmd [10 ] = { READ_CAPACITY };
720726 unsigned char buffer [8 ] = { };
721- int the_result ;
727+ struct queue_limits lim ;
728+ int err ;
722729 int sector_size ;
723- struct request_queue * queue ;
724730 struct scsi_failure failure_defs [] = {
725731 {
726732 .result = SCMD_FAILURE_RESULT_ANY ,
@@ -736,10 +742,10 @@ static void get_sectorsize(struct scsi_cd *cd)
736742 };
737743
738744 /* Do the command and wait.. */
739- the_result = scsi_execute_cmd (cd -> device , cmd , REQ_OP_DRV_IN , buffer ,
745+ err = scsi_execute_cmd (cd -> device , cmd , REQ_OP_DRV_IN , buffer ,
740746 sizeof (buffer ), SR_TIMEOUT , MAX_RETRIES ,
741747 & exec_args );
742- if (the_result ) {
748+ if (err ) {
743749 cd -> capacity = 0x1fffff ;
744750 sector_size = 2048 ; /* A guess, just in case */
745751 } else {
@@ -789,10 +795,12 @@ static void get_sectorsize(struct scsi_cd *cd)
789795 set_capacity (cd -> disk , cd -> capacity );
790796 }
791797
792- queue = cd -> device -> request_queue ;
793- blk_queue_logical_block_size (queue , sector_size );
794-
795- return ;
798+ lim = queue_limits_start_update (q );
799+ lim .logical_block_size = sector_size ;
800+ blk_mq_freeze_queue (q );
801+ err = queue_limits_commit_update (q , & lim );
802+ blk_mq_unfreeze_queue (q );
803+ return err ;
796804}
797805
798806static int get_capabilities (struct scsi_cd * cd )
0 commit comments