@@ -1643,24 +1643,21 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
16431643 return disk_changed ? DISK_EVENT_MEDIA_CHANGE : 0 ;
16441644}
16451645
1646- static int sd_sync_cache (struct scsi_disk * sdkp , struct scsi_sense_hdr * sshdr )
1646+ static int sd_sync_cache (struct scsi_disk * sdkp )
16471647{
16481648 int retries , res ;
16491649 struct scsi_device * sdp = sdkp -> device ;
16501650 const int timeout = sdp -> request_queue -> rq_timeout
16511651 * SD_FLUSH_TIMEOUT_MULTIPLIER ;
1652- struct scsi_sense_hdr my_sshdr ;
1652+ struct scsi_sense_hdr sshdr ;
16531653 const struct scsi_exec_args exec_args = {
16541654 .req_flags = BLK_MQ_REQ_PM ,
1655- /* caller might not be interested in sense, but we need it */
1656- .sshdr = sshdr ? : & my_sshdr ,
1655+ .sshdr = & sshdr ,
16571656 };
16581657
16591658 if (!scsi_device_online (sdp ))
16601659 return - ENODEV ;
16611660
1662- sshdr = exec_args .sshdr ;
1663-
16641661 for (retries = 3 ; retries > 0 ; -- retries ) {
16651662 unsigned char cmd [16 ] = { 0 };
16661663
@@ -1685,15 +1682,23 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
16851682 return res ;
16861683
16871684 if (scsi_status_is_check_condition (res ) &&
1688- scsi_sense_valid (sshdr )) {
1689- sd_print_sense_hdr (sdkp , sshdr );
1685+ scsi_sense_valid (& sshdr )) {
1686+ sd_print_sense_hdr (sdkp , & sshdr );
16901687
16911688 /* we need to evaluate the error return */
1692- if (sshdr -> asc == 0x3a || /* medium not present */
1693- sshdr -> asc == 0x20 || /* invalid command */
1694- (sshdr -> asc == 0x74 && sshdr -> ascq == 0x71 )) /* drive is password locked */
1689+ if (sshdr . asc == 0x3a || /* medium not present */
1690+ sshdr . asc == 0x20 || /* invalid command */
1691+ (sshdr . asc == 0x74 && sshdr . ascq == 0x71 )) /* drive is password locked */
16951692 /* this is no error here */
16961693 return 0 ;
1694+ /*
1695+ * This drive doesn't support sync and there's not much
1696+ * we can do because this is called during shutdown
1697+ * or suspend so just return success so those operations
1698+ * can proceed.
1699+ */
1700+ if (sshdr .sense_key == ILLEGAL_REQUEST )
1701+ return 0 ;
16971702 }
16981703
16991704 switch (host_byte (res )) {
@@ -3853,7 +3858,7 @@ static void sd_shutdown(struct device *dev)
38533858
38543859 if (sdkp -> WCE && sdkp -> media_present ) {
38553860 sd_printk (KERN_NOTICE , sdkp , "Synchronizing SCSI cache\n" );
3856- sd_sync_cache (sdkp , NULL );
3861+ sd_sync_cache (sdkp );
38573862 }
38583863
38593864 if ((system_state != SYSTEM_RESTART &&
@@ -3874,7 +3879,6 @@ static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime)
38743879static int sd_suspend_common (struct device * dev , bool runtime )
38753880{
38763881 struct scsi_disk * sdkp = dev_get_drvdata (dev );
3877- struct scsi_sense_hdr sshdr ;
38783882 int ret = 0 ;
38793883
38803884 if (!sdkp ) /* E.g.: runtime suspend following sd_remove() */
@@ -3883,24 +3887,13 @@ static int sd_suspend_common(struct device *dev, bool runtime)
38833887 if (sdkp -> WCE && sdkp -> media_present ) {
38843888 if (!sdkp -> device -> silence_suspend )
38853889 sd_printk (KERN_NOTICE , sdkp , "Synchronizing SCSI cache\n" );
3886- ret = sd_sync_cache (sdkp , & sshdr );
3887-
3888- if (ret ) {
3889- /* ignore OFFLINE device */
3890- if (ret == - ENODEV )
3891- return 0 ;
3892-
3893- if (!scsi_sense_valid (& sshdr ) ||
3894- sshdr .sense_key != ILLEGAL_REQUEST )
3895- return ret ;
3890+ ret = sd_sync_cache (sdkp );
3891+ /* ignore OFFLINE device */
3892+ if (ret == - ENODEV )
3893+ return 0 ;
38963894
3897- /*
3898- * sshdr.sense_key == ILLEGAL_REQUEST means this drive
3899- * doesn't support sync. There's not much to do and
3900- * suspend shouldn't fail.
3901- */
3902- ret = 0 ;
3903- }
3895+ if (ret )
3896+ return ret ;
39043897 }
39053898
39063899 if (sd_do_start_stop (sdkp -> device , runtime )) {
0 commit comments