All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dolev Raviv <draviv@codeaurora.org>
To: James.Bottomley@HansenPartnership.com, hch@infradead.org
Cc: linux-scsi@vger.kernel.org, linux-scsi-owner@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, santoshsy@gmail.com,
	Sujit Reddy Thumma <sthumma@codeaurora.org>,
	Dolev Raviv <draviv@codeaurora.org>
Subject: [RFC 09/10] scsi: sd: Avoid sending medium write commands if device is write protected
Date: Mon, 11 Aug 2014 15:40:37 +0300	[thread overview]
Message-ID: <1407760838-6406-10-git-send-email-draviv@codeaurora.org> (raw)
In-Reply-To: <1407760838-6406-1-git-send-email-draviv@codeaurora.org>

From: Sujit Reddy Thumma <sthumma@codeaurora.org>

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>

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3663e38..67282bf 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -185,7 +185,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
 	if (ct < 0)
 		return -EINVAL;
 	rcd = ct & 0x01 ? 1 : 0;
-	wce = ct & 0x02 ? 1 : 0;
+	wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0;
 
 	if (sdkp->cache_override) {
 		sdkp->WCE = wce;
@@ -2493,6 +2493,10 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 			sdkp->DPOFUA = 0;
 		}
 
+		/* No cache flush allowed for write protected devices */
+		if (sdkp->WCE && sdkp->write_prot)
+			sdkp->WCE = 0;
+
 		if (sdkp->first_scan || old_wce != sdkp->WCE ||
 		    old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA)
 			sd_printk(KERN_NOTICE, sdkp,
-- 
1.8.5.2
-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

  parent reply	other threads:[~2014-08-11 12:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-11 12:40 [RFC 00/10] UFS: Power managment support Dolev Raviv
2014-08-11 12:40 ` [RFC 01/10] scsi: ufs: Allow vendor specific initialization Dolev Raviv
2014-08-11 12:40 ` [RFC 02/10] scsi: ufs: Add regulator enable support Dolev Raviv
2014-08-11 12:40 ` [RFC 03/10] scsi: ufs: Add clock initialization support Dolev Raviv
2014-08-11 12:40 ` [RFC 04/10] scsi: ufs: refactor query descriptor API support Dolev Raviv
2014-08-11 12:40 ` [RFC 05/10] scsi: ufs: improve init sequence Dolev Raviv
2014-08-11 12:40 ` [RFC 06/10] scsi: ufs: Active Power Mode - configuring bActiveICCLevel Dolev Raviv
2014-08-11 12:40 ` [RFC 07/10] scsi: support well known logical units Dolev Raviv
2014-08-11 12:40 ` [RFC 08/10] scsi: ufs: introduce well known logical unit in ufs Dolev Raviv
2014-08-11 12:40 ` Dolev Raviv [this message]
2014-08-19 17:30   ` [RFC 09/10] scsi: sd: Avoid sending medium write commands if device is write protected Christoph Hellwig
2014-08-20 13:24     ` Martin K. Petersen
2014-08-19 17:55   ` Venkatesh Srinivas
2014-08-24 16:28   ` [RFC 09/10] " Christoph Hellwig
2014-08-11 12:40 ` [RFC 10/10] scsi: ufs: add UFS power management support Dolev Raviv

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407760838-6406-10-git-send-email-draviv@codeaurora.org \
    --to=draviv@codeaurora.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=hch@infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-scsi-owner@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=santoshsy@gmail.com \
    --cc=sthumma@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.