Skip to contentSkip to conversation

libata-scsi: better style in ata_msense_caching()

PATCH Applied [email protected] 2 participants 16 messages Jul 12, 2016 – Jul 20, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20160712133703.2076-1-me

#1 lore raw

PATCH v3 2/2 libata-scsi: better style in ata_msense_caching()

From: Tom Yan <[email protected]>

drivers/ata/libata-scsi.c +6 -4
index bfec66f..48ea887 100644
@@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
 static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
 {
 	modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);
-	if (changeable || ata_id_wcache_enabled(id))
-		buf[2] |= (1 << 2);	/* write cache enable */
-	if (!changeable && !ata_id_rahead_enabled(id))
-		buf[12] |= (1 << 5);	/* disable read ahead */
+	if (changeable) {
+		buf[2] |= 1 << 2; /* ata_mselect_caching() */
+	} else {
+		buf[2] |= ata_id_wcache_enabled(id) << 2;	/* write cache enable */
+		buf[12] |= !ata_id_rahead_enabled(id) << 5;	/* disable read ahead */
+	}
 	return sizeof(def_cache_mpage);
 }
 
Signature · 1 line
2.9.0
#2 lore raw
Quoted 12 lines · On Tue, Jul 12, 2016 at 09:37:03PM +0800, [email protected] wrote:

From: Tom Yan <[email protected]>

drivers/ata/libata-scsi.c +0 -0
index bfec66f..48ea887 100644
@@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
 static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
 {
 	modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);

drivers/ata/libata-scsi.c static void modecpy(u8 *dest, const u8 *src, int n, bool changeable) · line 2432

Quoted 10 lines
drivers/ata/libata-scsi.c +6 -4
-	if (changeable || ata_id_wcache_enabled(id))
-		buf[2] |= (1 << 2);	/* write cache enable */
-	if (!changeable && !ata_id_rahead_enabled(id))
-		buf[12] |= (1 << 5);	/* disable read ahead */
+	if (changeable) {
+		buf[2] |= 1 << 2; /* ata_mselect_caching() */
+	} else {
+		buf[2] |= ata_id_wcache_enabled(id) << 2;	/* write cache enable */
+		buf[12] |= !ata_id_rahead_enabled(id) << 5;	/* disable read ahead */
+	}

It's different but I'm not sure this is better.

Thanks.

Signature · 1 line
tejun
author
#3 lore raw

First of all "changeable" is the "version" of mode page requested by the user, while ata_id_*_enabled(id) are the value of setting reported by the device. I think it's ugly and confusing to check values of totally different nature "together".

The worse thing is, since we have implemented MODE SELECT / ata_mselect_caching() to serve exclusively the write cache feature, the difference in the two if-conditions made the code look even more arcane.

In my version, it is clear that when the user request the changeable mode page, the value for the WCE bit will always be "1" / "y", since we've made (only) it changeable in ata_mselect_caching(); and when the user request the current / default page, the values reflect the settings from the drive.

Quoted 30 lines · Tejun Heo
Quoted 12 lines · On Tue, Jul 12, 2016 at 09:37:03PM +0800, [email protected] wrote:

From: Tom Yan <[email protected]>

drivers/ata/libata-scsi.c +0 -0
index bfec66f..48ea887 100644
@@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
 static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
 {
      modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);

drivers/ata/libata-scsi.c static void modecpy(u8 *dest, const u8 *src, int n, bool changeable) · line 2432

Quoted 10 lines
drivers/ata/libata-scsi.c +6 -4
-     if (changeable || ata_id_wcache_enabled(id))
-             buf[2] |= (1 << 2);     /* write cache enable */
-     if (!changeable && !ata_id_rahead_enabled(id))
-             buf[12] |= (1 << 5);    /* disable read ahead */
+     if (changeable) {
+             buf[2] |= 1 << 2; /* ata_mselect_caching() */
+     } else {
+             buf[2] |= ata_id_wcache_enabled(id) << 2;       /* write cache enable */
+             buf[12] |= !ata_id_rahead_enabled(id) << 5;     /* disable read ahead */
+     }

It's different but I'm not sure this is better.

Thanks.

--
tejun

#4 lore raw
Quoted 10 lines · Tom Yan

First of all "changeable" is the "version" of mode page requested by the user, while ata_id_*_enabled(id) are the value of setting reported by the device. I think it's ugly and confusing to check values of totally different nature "together".

The worse thing is, since we have implemented MODE SELECT / ata_mselect_caching() to serve exclusively the write cache feature, the difference in the two if-conditions made the code look even more arcane.

Quoted 5 lines

In my version, it is clear that when the user request the changeable mode page, the value for the WCE bit will always be "1" / "y", since we've made (only) it changeable in ata_mselect_caching(); and when the user request the current / default page, the values reflect the settings from the drive.

Can you please put the rationale in the patch description and repost?

Thanks.

Signature · 1 line
tejun
author
#5 lore raw

Sure. I was checking whether other MODE SENSE functions have the same problem. It turns out the recently rewritten ata_msense_ctl_mode() is actually bugged, seemingly because of the original arcane style. Sent the patch for that, fixing it in the original style.

So I am wondering if I should further fix the style of ata_msense_ctl_mode() when I resend this patch. If so, how should I make dev->flags & ATA_DFLAG_D_SENSE a boolean, so that it can be bit shifted? Double negation? Type casting? Or should I just use an else if clause?

Quoted 23 lines · Tejun Heo
Quoted 10 lines · Tom Yan

First of all "changeable" is the "version" of mode page requested by the user, while ata_id_*_enabled(id) are the value of setting reported by the device. I think it's ugly and confusing to check values of totally different nature "together".

The worse thing is, since we have implemented MODE SELECT / ata_mselect_caching() to serve exclusively the write cache feature, the difference in the two if-conditions made the code look even more arcane.

Quoted 5 lines

In my version, it is clear that when the user request the changeable mode page, the value for the WCE bit will always be "1" / "y", since we've made (only) it changeable in ata_mselect_caching(); and when the user request the current / default page, the values reflect the settings from the drive.

Can you please put the rationale in the patch description and repost?

Thanks.

--
tejun

#6 lore raw

PATCH v4 1/1 libata-scsi: better style in ata_msense_*()

In reply to [email protected]

From: Tom Yan <[email protected]>

changeable is the "version" of mode page requested by the user. It will be less confusing/misleading if we do not check it "together" with the setting bits of the drive.

Not to mention that we currently have ata_mselect_*() implemented in a way that each of them will serve exclusively a particular bit on each page. The old style will hence make the condition look even more unnecessarily arcane if the ata_msense_*() is reflecting more than one bit.

drivers/ata/libata-scsi.c +13 -6
index bf4cb21..b00521b 100644
@@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
 static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
 {
 	modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);
-	if (changeable || ata_id_wcache_enabled(id))
-		buf[2] |= (1 << 2);	/* write cache enable */
-	if (!changeable && !ata_id_rahead_enabled(id))
-		buf[12] |= (1 << 5);	/* disable read ahead */
+	if (changeable) {
+		buf[2] |= (1 << 2);	/* ata_mselect_caching() */
+	} else {
+		buf[2] |= (ata_id_wcache_enabled(id) << 2);	/* write cache enable */
+		buf[12] |= (!ata_id_rahead_enabled(id) << 5);	/* disable read ahead */
+	}
 	return sizeof(def_cache_mpage);
 }
 
@@ -2446,8 +2448,13 @@ static unsigned int ata_msense_control(struct ata_device *dev, u8 *buf,
 					bool changeable)
 {
 	modecpy(buf, def_control_mpage, sizeof(def_control_mpage), changeable);
-	if (changeable || (dev->flags & ATA_DFLAG_D_SENSE))
-		buf[2] |= (1 << 2);	/* Descriptor sense requested */
+	if (changeable) {
+		buf[2] |= (1 << 2);	/* ata_mselect_control() */
+	} else {
+		bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE);
+
+		buf[2] |= (d_sense << 2);	/* descriptor format sense data */
+	}
 	return sizeof(def_control_mpage);
 }
 
Signature · 1 line
2.9.0
author
#7 lore raw

Re: [PATCH v4] libata-scsi: better style in ata_msense_*()

FWIW, I end up using bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE), which was introduced to ata_scsi_set_sense() in commit 06dbde5f3a44 ("libata: Implement control mode page to select sense format"), in the polished ata_msense_control().

@Sergei, I kept the parentheses for the bit shifting/masking results because it appears that the rest of the code in libata-scsi.c does that as well. So I am not going to partially clean up that to avoid making it look inconsistent.

Quoted 54 lines · On 20 July 2016 at 04:39, <[email protected]> wrote:

From: Tom Yan <[email protected]>

changeable is the "version" of mode page requested by the user. It will be less confusing/misleading if we do not check it "together" with the setting bits of the drive.

Not to mention that we currently have ata_mselect_*() implemented in a way that each of them will serve exclusively a particular bit on each page. The old style will hence make the condition look even more unnecessarily arcane if the ata_msense_*() is reflecting more than one bit.

drivers/ata/libata-scsi.c +13 -7
index bf4cb21..b00521b 100644
@@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
 static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
 {
        modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);
-       if (changeable || ata_id_wcache_enabled(id))
-               buf[2] |= (1 << 2);     /* write cache enable */
-       if (!changeable && !ata_id_rahead_enabled(id))
-               buf[12] |= (1 << 5);    /* disable read ahead */
+       if (changeable) {
+               buf[2] |= (1 << 2);     /* ata_mselect_caching() */
+       } else {
+               buf[2] |= (ata_id_wcache_enabled(id) << 2);     /* write cache enable */
+               buf[12] |= (!ata_id_rahead_enabled(id) << 5);   /* disable read ahead */
+       }
        return sizeof(def_cache_mpage);
 }
 
@@ -2446,8 +2448,13 @@ static unsigned int ata_msense_control(struct ata_device *dev, u8 *buf,
                                        bool changeable)
 {
        modecpy(buf, def_control_mpage, sizeof(def_control_mpage), changeable);
-       if (changeable || (dev->flags & ATA_DFLAG_D_SENSE))
-               buf[2] |= (1 << 2);     /* Descriptor sense requested */
+       if (changeable) {
+               buf[2] |= (1 << 2);     /* ata_mselect_control() */
+       } else {
+               bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE);
+
+               buf[2] |= (d_sense << 2);       /* descriptor format sense data */
+       }
        return sizeof(def_control_mpage);
 }
 
--

2.9.0

#8 lore raw

PATCH v4 1/1 libata-scsi: minor cleanup in ata_mselect_*()

In reply to [email protected]

From: Tom Yan <[email protected]>

1. Removed a repeated bit masking in ata_mselect_control()
2. Moved wce/d_sense assignment below the page validity checks
3. Added/Removed empty lines where appropriate

drivers/ata/libata-scsi.c +6 -7
index b00521b..06afe63 100644
@@ -3604,7 +3604,6 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
 	 * The first two bytes of def_cache_mpage are a header, so offsets
 	 * in mpage are off by 2 compared to buf.  Same for len.
 	 */
-
 	if (len != CACHE_MPAGE_LEN - 2) {
 		if (len < CACHE_MPAGE_LEN - 2)
 			*fp = len;
@@ -3613,8 +3612,6 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
 		return -EINVAL;
 	}
 
-	wce = buf[0] & (1 << 2);
-
 	/*
 	 * Check that read-only bits are not modified.
 	 */
@@ -3628,6 +3625,8 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
 		}
 	}
 
+	wce = buf[0] & (1 << 2);
+
 	tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
 	tf->protocol = ATA_PROT_NODATA;
 	tf->nsect = 0;
@@ -3660,7 +3659,6 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
 	 * The first two bytes of def_control_mpage are a header, so offsets
 	 * in mpage are off by 2 compared to buf.  Same for len.
 	 */
-
 	if (len != CONTROL_MPAGE_LEN - 2) {
 		if (len < CONTROL_MPAGE_LEN - 2)
 			*fp = len;
@@ -3669,8 +3667,6 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
 		return -EINVAL;
 	}
 
-	d_sense = buf[0] & (1 << 2);
-
 	/*
 	 * Check that read-only bits are not modified.
 	 */
@@ -3683,7 +3679,10 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
 			return -EINVAL;
 		}
 	}
-	if (d_sense & (1 << 2))
+
+	d_sense = buf[0] & (1 << 2);
+
+	if (d_sense)
 		dev->flags |= ATA_DFLAG_D_SENSE;
 	else
 		dev->flags &= ~ATA_DFLAG_D_SENSE;
Signature · 1 line
2.9.0
#9 lore raw

PATCH 1/1 libata-scsi: fix read-only bits checking in ata_mselect_*()

From: Tom Yan <[email protected]>

Commit 7780081c1f04 ("libata-scsi: Set information sense field for invalid parameter") changed how ata_mselect_*() make sure read-only bits are not modified. The new implementation introduced a bug that the read-only bits in the byte that has a changeable bit will not be checked.

Added the necessary check, with comments explaining the heuristic.

drivers/ata/libata-scsi.c +24 -4
index 06afe63..005d186 100644
@@ -3617,8 +3617,18 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
 	 */
 	ata_msense_caching(dev->id, mpage, false);
 	for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) {
-		if (i == 0)
-			continue;
+		/* Check the first byte */
+		if (i == 0) {
+			/* except the WCE bit */
+			if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {
+				continue;
+			} else {
+				*fp = i;
+				return -EINVAL;
+			}
+		}
+
+		/* Check the remaining bytes */
 		if (mpage[i + 2] != buf[i]) {
 			*fp = i;
 			return -EINVAL;
@@ -3672,8 +3682,18 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
 	 */
 	ata_msense_control(dev, mpage, false);
 	for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) {
-		if (i == 0)
-			continue;
+		/* Check the first byte */
+		if (i == 0) {
+			/* except the D_SENSE bit */
+			if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {
+				continue;
+			} else {
+				*fp = i;
+				return -EINVAL;
+			}
+		}
+
+		/* Check the remaining bytes */
 		if (mpage[2 + i] != buf[i]) {
 			*fp = i;
 			return -EINVAL;
Signature · 1 line
2.9.0
author
#10 lore raw

Re: [PATCH] libata-scsi: fix read-only bits checking in ata_mselect_*()

Oops I put the wrong action under the opposite condition. Sending a v2.

Quoted 61 lines · On 20 July 2016 at 06:50, <[email protected]> wrote:

From: Tom Yan <[email protected]>

Commit 7780081c1f04 ("libata-scsi: Set information sense field for invalid parameter") changed how ata_mselect_*() make sure read-only bits are not modified. The new implementation introduced a bug that the read-only bits in the byte that has a changeable bit will not be checked.

Added the necessary check, with comments explaining the heuristic.

drivers/ata/libata-scsi.c +24 -5
index 06afe63..005d186 100644
@@ -3617,8 +3617,18 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
         */
        ata_msense_caching(dev->id, mpage, false);
        for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) {
-               if (i == 0)
-                       continue;
+               /* Check the first byte */
+               if (i == 0) {
+                       /* except the WCE bit */
+                       if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {
+                               continue;
+                       } else {
+                               *fp = i;
+                               return -EINVAL;
+                       }
+               }
+
+               /* Check the remaining bytes */
                if (mpage[i + 2] != buf[i]) {
                        *fp = i;
                        return -EINVAL;
@@ -3672,8 +3682,18 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
         */
        ata_msense_control(dev, mpage, false);
        for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) {
-               if (i == 0)
-                       continue;
+               /* Check the first byte */
+               if (i == 0) {
+                       /* except the D_SENSE bit */
+                       if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {
+                               continue;
+                       } else {
+                               *fp = i;
+                               return -EINVAL;
+                       }
+               }
+
+               /* Check the remaining bytes */
                if (mpage[2 + i] != buf[i]) {
                        *fp = i;
                        return -EINVAL;
--

2.9.0

#11 lore raw

PATCH v2 1/1 libata-scsi: fix read-only bits checking in ata_mselect_*()

In reply to [email protected]

From: Tom Yan <[email protected]>

Commit 7780081c1f04 ("libata-scsi: Set information sense field for invalid parameter") changed how ata_mselect_*() make sure read-only bits are not modified. The new implementation introduced a bug that the read-only bits in the byte that has a changeable bit will not be checked.

Added the necessary check, with comments explaining the heuristic.

drivers/ata/libata-scsi.c +24 -4
index 06afe63..b47c3ce 100644
@@ -3617,8 +3617,18 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
 	 */
 	ata_msense_caching(dev->id, mpage, false);
 	for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) {
-		if (i == 0)
-			continue;
+		/* Check the first byte */
+		if (i == 0) {
+			/* except the WCE bit */
+			if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {
+				*fp = i;
+				return -EINVAL;
+			} else {
+				continue;
+			}
+		}
+
+		/* Check the remaining bytes */
 		if (mpage[i + 2] != buf[i]) {
 			*fp = i;
 			return -EINVAL;
@@ -3672,8 +3682,18 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
 	 */
 	ata_msense_control(dev, mpage, false);
 	for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) {
-		if (i == 0)
-			continue;
+		/* Check the first byte */
+		if (i == 0) {
+			/* except the D_SENSE bit */
+			if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {
+				*fp = i;
+				return -EINVAL;
+			} else {
+				continue;
+			}
+		}
+
+		/* Check the remaining bytes */
 		if (mpage[2 + i] != buf[i]) {
 			*fp = i;
 			return -EINVAL;
Signature · 1 line
2.9.0
Applied
#12 lore raw

Re: [PATCH v2] libata-scsi: fix read-only bits checking in ata_mselect_*()

Quoted 11 lines · On Wed, Jul 20, 2016 at 06:59:23AM +0800, [email protected] wrote:

From: Tom Yan <[email protected]>

Commit 7780081c1f04 ("libata-scsi: Set information sense field for invalid parameter") changed how ata_mselect_*() make sure read-only bits are not modified. The new implementation introduced a bug that the read-only bits in the byte that has a changeable bit will not be checked.

Added the necessary check, with comments explaining the heuristic.

Applied to libata/for-4.8.

This thread was confusing to look at. Please use the "n/N" sequence tagging for the patches (the -n option of git-format-patch).

Thanks.

Signature · 1 line
tejun
#13 lore raw

Re: [PATCH v2] libata-scsi: fix read-only bits checking in ata_mselect_*()

In reply to [email protected]

So, just reverted this patch.

Quoted 17 lines · On Wed, Jul 20, 2016 at 06:59:23AM +0800, [email protected] wrote:

From: Tom Yan <[email protected]>

Commit 7780081c1f04 ("libata-scsi: Set information sense field for invalid parameter") changed how ata_mselect_*() make sure read-only bits are not modified. The new implementation introduced a bug that the read-only bits in the byte that has a changeable bit will not be checked.

Added the necessary check, with comments explaining the heuristic.

drivers/ata/libata-scsi.c +0 -0
index 06afe63..b47c3ce 100644

drivers/ata/libata-scsi.c static int ata_mselect_caching(struct ata_queued_cmd *qc, · line 3623

Quoted 9 lines
drivers/ata/libata-scsi.c +4 -2
@@ -3617,8 +3617,18 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
 	 */
 	ata_msense_caching(dev->id, mpage, false);
 	for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) {
-		if (i == 0)
-			continue;
+		/* Check the first byte */
+		if (i == 0) {
+			/* except the WCE bit */
+			if (mpage[i + 2] & 0xfb != buf[i] & 0xfb) {

This not only triggered compiler warning but is actually wrong. The above is

	mpage[i + 1] & (0xfb != buf[i]) & 0xfb

which is non-sensical. So, this patch wasn't tested at all. Not even compile test. Please don't do this.

Thanks.

Signature · 1 line
tejun
author
#14 lore raw

Re: [PATCH v4] libata-scsi: minor cleanup in ata_mselect_*()

In reply to [email protected]

Wrongly marked this as a "v4". It's actually a "v1".

Quoted 70 lines · On 20 July 2016 at 05:11, <[email protected]> wrote:

From: Tom Yan <[email protected]>

1. Removed a repeated bit masking in ata_mselect_control()
2. Moved wce/d_sense assignment below the page validity checks
3. Added/Removed empty lines where appropriate

drivers/ata/libata-scsi.c +6 -8
index b00521b..06afe63 100644
@@ -3604,7 +3604,6 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
         * The first two bytes of def_cache_mpage are a header, so offsets
         * in mpage are off by 2 compared to buf.  Same for len.
         */
-
        if (len != CACHE_MPAGE_LEN - 2) {
                if (len < CACHE_MPAGE_LEN - 2)
                        *fp = len;
@@ -3613,8 +3612,6 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
                return -EINVAL;
        }
 
-       wce = buf[0] & (1 << 2);
-
        /*
         * Check that read-only bits are not modified.
         */
@@ -3628,6 +3625,8 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,
                }
        }
 
+       wce = buf[0] & (1 << 2);
+
        tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
        tf->protocol = ATA_PROT_NODATA;
        tf->nsect = 0;
@@ -3660,7 +3659,6 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
         * The first two bytes of def_control_mpage are a header, so offsets
         * in mpage are off by 2 compared to buf.  Same for len.
         */
-
        if (len != CONTROL_MPAGE_LEN - 2) {
                if (len < CONTROL_MPAGE_LEN - 2)
                        *fp = len;
@@ -3669,8 +3667,6 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
                return -EINVAL;
        }
 
-       d_sense = buf[0] & (1 << 2);
-
        /*
         * Check that read-only bits are not modified.
         */
@@ -3683,7 +3679,10 @@ static int ata_mselect_control(struct ata_queued_cmd *qc,
                        return -EINVAL;
                }
        }
-       if (d_sense & (1 << 2))
+
+       d_sense = buf[0] & (1 << 2);
+
+       if (d_sense)
                dev->flags |= ATA_DFLAG_D_SENSE;
        else
                dev->flags &= ~ATA_DFLAG_D_SENSE;
--

2.9.0

Applied
#15 lore raw

Re: [PATCH v4] libata-scsi: minor cleanup in ata_mselect_*()

In reply to [email protected]
Quoted 7 lines · On Wed, Jul 20, 2016 at 05:11:50AM +0800, [email protected] wrote:

From: Tom Yan <[email protected]>

1. Removed a repeated bit masking in ata_mselect_control()
2. Moved wce/d_sense assignment below the page validity checks
3. Added/Removed empty lines where appropriate

Applied to libata/for-4.8.

Thanks.

Signature · 1 line
tejun
Applied
#16 lore raw

Re: [PATCH v4] libata-scsi: better style in ata_msense_*()

In reply to [email protected]
Quoted 6 lines · On Wed, Jul 20, 2016 at 04:39:28AM +0800, [email protected] wrote:

From: Tom Yan <[email protected]>

changeable is the "version" of mode page requested by the user. It will be less confusing/misleading if we do not check it "together" with the setting bits of the drive.

Quoted 7 lines

Not to mention that we currently have ata_mselect_*() implemented in a way that each of them will serve exclusively a particular bit on each page. The old style will hence make the condition look even more unnecessarily arcane if the ata_msense_*() is reflecting more than one bit.

Applied to libata/for-4.8.

Thanks.

Signature · 1 line
tejun