Skip to content

Commit 476c7e1

Browse files
Dan Carpenterbbrezillon
authored andcommitted
i3c: Fix a shift wrap bug in i3c_bus_set_addr_slot_status()
The problem here is that addr can be I3C_BROADCAST_ADDR (126). That means we're shifting by (126 * 2) % 64 which is 60. The I3C_ADDR_SLOT_STATUS_MASK is an enum which is an unsigned int in GCC so shifts greater than 31 are undefined. Fixes: 3a379bb ("i3c: Add core I3C infrastructure") Cc: <[email protected]> Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Boris Brezillon <[email protected]>
1 parent 124dbd7 commit 476c7e1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/i3c/master.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
385385
return;
386386

387387
ptr = bus->addrslots + (bitpos / BITS_PER_LONG);
388-
*ptr &= ~(I3C_ADDR_SLOT_STATUS_MASK << (bitpos % BITS_PER_LONG));
389-
*ptr |= status << (bitpos % BITS_PER_LONG);
388+
*ptr &= ~((unsigned long)I3C_ADDR_SLOT_STATUS_MASK <<
389+
(bitpos % BITS_PER_LONG));
390+
*ptr |= (unsigned long)status << (bitpos % BITS_PER_LONG);
390391
}
391392

392393
static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr)

0 commit comments

Comments
 (0)