Skip to content

Commit beecade

Browse files
xiwJames Bottomley
authored and
James Bottomley
committed
[SCSI] mvsas: fix undefined bit shift
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 <[email protected]> Acked-by: Xiangliang Yu <[email protected]> Cc: [email protected] Signed-off-by: James Bottomley <[email protected]>
1 parent 072f19b commit beecade

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

drivers/scsi/mvsas/mv_94xx.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,11 @@ enum sas_sata_phy_regs {
258258
#define SPI_ADDR_VLD_94XX (1U << 1)
259259
#define SPI_CTRL_SpiStart_94XX (1U << 0)
260260

261-
#define mv_ffc(x) ffz(x)
262-
263261
static inline int
264262
mv_ffc64(u64 v)
265263
{
266-
int i;
267-
i = mv_ffc((u32)v);
268-
if (i >= 0)
269-
return i;
270-
i = mv_ffc((u32)(v>>32));
271-
272-
if (i != 0)
273-
return 32 + i;
274-
275-
return -1;
264+
u64 x = ~v;
265+
return x ? __ffs64(x) : -1;
276266
}
277267

278268
#define r_reg_set_enable(i) \

drivers/scsi/mvsas/mv_sas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern struct kmem_cache *mvs_task_list_cache;
6969
#define DEV_IS_EXPANDER(type) \
7070
((type == EDGE_DEV) || (type == FANOUT_DEV))
7171

72-
#define bit(n) ((u32)1 << n)
72+
#define bit(n) ((u64)1 << n)
7373

7474
#define for_each_phy(__lseq_mask, __mc, __lseq) \
7575
for ((__mc) = (__lseq_mask), (__lseq) = 0; \

0 commit comments

Comments
 (0)