From: Xi Wang <xi.wang@gmail.com>
To: Xiangliang Yu <yuxiangl@marvell.com>,
"James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v2] [SCSI] mvsas: fix undefined bit shift
Date: Fri, 16 Nov 2012 14:40:03 -0500 [thread overview]
Message-ID: <50A69693.2050002@gmail.com> (raw)
In-Reply-To: <1352145183-29355-1-git-send-email-xi.wang@gmail.com>
The macro bit(n) is defined as ((u32)1 << n), and thus it doesn't work
with n >= 32, such as in mvs_94xx_assign_reg_set():
if (i >= 32) {
mvi->sata_reg_set |= bit(i);
...
}
The shift ((u32)1 << n) with n >= 32 also leads to undefined behavior.
The result varies depending on the architecture.
This patch changes bit(n) to do a 64-bit shift. It also simplifies
mv_ffc64() using __ffs64(), since invoking ffz() with ~0 is undefined.
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Cc: Xiangliang Yu <yuxiangl@marvell.com>
Cc: James Bottomley <JBottomley@Parallels.com>
Cc: stable@vger.kernel.org
---
As suggested by James, v2 is a single patch with a stable tag.
---
drivers/scsi/mvsas/mv_94xx.h | 14 ++------------
drivers/scsi/mvsas/mv_sas.h | 2 +-
2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/drivers/scsi/mvsas/mv_94xx.h b/drivers/scsi/mvsas/mv_94xx.h
index 8f7eb4f..487aa6f 100644
--- a/drivers/scsi/mvsas/mv_94xx.h
+++ b/drivers/scsi/mvsas/mv_94xx.h
@@ -258,21 +258,11 @@ enum sas_sata_phy_regs {
#define SPI_ADDR_VLD_94XX (1U << 1)
#define SPI_CTRL_SpiStart_94XX (1U << 0)
-#define mv_ffc(x) ffz(x)
-
static inline int
mv_ffc64(u64 v)
{
- int i;
- i = mv_ffc((u32)v);
- if (i >= 0)
- return i;
- i = mv_ffc((u32)(v>>32));
-
- if (i != 0)
- return 32 + i;
-
- return -1;
+ u64 x = ~v;
+ return x ? __ffs64(x) : -1;
}
#define r_reg_set_enable(i) \
diff --git a/drivers/scsi/mvsas/mv_sas.h b/drivers/scsi/mvsas/mv_sas.h
index c04a4f5..da24955 100644
--- a/drivers/scsi/mvsas/mv_sas.h
+++ b/drivers/scsi/mvsas/mv_sas.h
@@ -69,7 +69,7 @@ extern struct kmem_cache *mvs_task_list_cache;
#define DEV_IS_EXPANDER(type) \
((type == EDGE_DEV) || (type == FANOUT_DEV))
-#define bit(n) ((u32)1 << n)
+#define bit(n) ((u64)1 << n)
#define for_each_phy(__lseq_mask, __mc, __lseq) \
for ((__mc) = (__lseq_mask), (__lseq) = 0; \
--
1.7.10.4
prev parent reply other threads:[~2012-11-16 19:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-05 19:53 [PATCH 0/3] [SCSI] mvsas: fix multiple shift issues Xi Wang
2012-11-05 19:53 ` [PATCH 1/3] [SCSI] mvsas: fix shift in mvs_94xx_assign_reg_set() Xi Wang
2012-11-05 19:53 ` [PATCH 2/3] [SCSI] mvsas: fix shift in mvs_94xx_free_reg_set() Xi Wang
2012-11-06 12:06 ` James Bottomley
2012-11-06 20:55 ` Xi Wang
2012-11-09 7:30 ` Xiangliang Yu
2012-11-09 13:44 ` Xi Wang
2012-11-16 7:39 ` Xiangliang Yu
2012-11-05 19:53 ` [PATCH 3/3] [SCSI] mvsas: fix shift in mv_ffc64() Xi Wang
2012-11-16 19:40 ` Xi Wang [this message]
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=50A69693.2050002@gmail.com \
--to=xi.wang@gmail.com \
--cc=JBottomley@parallels.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=yuxiangl@marvell.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).