Commit 2eefd57b97609949ae40952da2dea338e7d9a125
Committed by
Christoph Hellwig
1 parent
74cf298fed
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
sd: Avoid sending medium write commands if device is write protected
The SYNCHRONIZE_CACHE command is a medium write command and hence can fail when the device is write protected. Avoid sending such commands by making sure that write-cache-enable is disabled even though the device claim to support it. Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org> Signed-off-by: Dolev Raviv <draviv@codeaurora.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Venkatesh Srinivas <venkateshs@google.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Showing 1 changed file with 5 additions and 1 deletions Side-by-side Diff
drivers/scsi/sd.c
... | ... | @@ -185,7 +185,7 @@ |
185 | 185 | if (ct < 0) |
186 | 186 | return -EINVAL; |
187 | 187 | rcd = ct & 0x01 ? 1 : 0; |
188 | - wce = ct & 0x02 ? 1 : 0; | |
188 | + wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0; | |
189 | 189 | |
190 | 190 | if (sdkp->cache_override) { |
191 | 191 | sdkp->WCE = wce; |
... | ... | @@ -2489,6 +2489,10 @@ |
2489 | 2489 | "Uses READ/WRITE(6), disabling FUA\n"); |
2490 | 2490 | sdkp->DPOFUA = 0; |
2491 | 2491 | } |
2492 | + | |
2493 | + /* No cache flush allowed for write protected devices */ | |
2494 | + if (sdkp->WCE && sdkp->write_prot) | |
2495 | + sdkp->WCE = 0; | |
2492 | 2496 | |
2493 | 2497 | if (sdkp->first_scan || old_wce != sdkp->WCE || |
2494 | 2498 | old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA) |