@@ -1643,24 +1643,21 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
1643
1643
return disk_changed ? DISK_EVENT_MEDIA_CHANGE : 0 ;
1644
1644
}
1645
1645
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 )
1647
1647
{
1648
1648
int retries , res ;
1649
1649
struct scsi_device * sdp = sdkp -> device ;
1650
1650
const int timeout = sdp -> request_queue -> rq_timeout
1651
1651
* SD_FLUSH_TIMEOUT_MULTIPLIER ;
1652
- struct scsi_sense_hdr my_sshdr ;
1652
+ struct scsi_sense_hdr sshdr ;
1653
1653
const struct scsi_exec_args exec_args = {
1654
1654
.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 ,
1657
1656
};
1658
1657
1659
1658
if (!scsi_device_online (sdp ))
1660
1659
return - ENODEV ;
1661
1660
1662
- sshdr = exec_args .sshdr ;
1663
-
1664
1661
for (retries = 3 ; retries > 0 ; -- retries ) {
1665
1662
unsigned char cmd [16 ] = { 0 };
1666
1663
@@ -1685,15 +1682,23 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
1685
1682
return res ;
1686
1683
1687
1684
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 );
1690
1687
1691
1688
/* 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 */
1695
1692
/* this is no error here */
1696
1693
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 ;
1697
1702
}
1698
1703
1699
1704
switch (host_byte (res )) {
@@ -3853,7 +3858,7 @@ static void sd_shutdown(struct device *dev)
3853
3858
3854
3859
if (sdkp -> WCE && sdkp -> media_present ) {
3855
3860
sd_printk (KERN_NOTICE , sdkp , "Synchronizing SCSI cache\n" );
3856
- sd_sync_cache (sdkp , NULL );
3861
+ sd_sync_cache (sdkp );
3857
3862
}
3858
3863
3859
3864
if ((system_state != SYSTEM_RESTART &&
@@ -3874,7 +3879,6 @@ static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime)
3874
3879
static int sd_suspend_common (struct device * dev , bool runtime )
3875
3880
{
3876
3881
struct scsi_disk * sdkp = dev_get_drvdata (dev );
3877
- struct scsi_sense_hdr sshdr ;
3878
3882
int ret = 0 ;
3879
3883
3880
3884
if (!sdkp ) /* E.g.: runtime suspend following sd_remove() */
@@ -3883,24 +3887,13 @@ static int sd_suspend_common(struct device *dev, bool runtime)
3883
3887
if (sdkp -> WCE && sdkp -> media_present ) {
3884
3888
if (!sdkp -> device -> silence_suspend )
3885
3889
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 ;
3896
3894
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 ;
3904
3897
}
3905
3898
3906
3899
if (sd_do_start_stop (sdkp -> device , runtime )) {
0 commit comments