i3c: Fix a shift wrap bug in i3c_bus_set_addr_slot_status()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 23 Apr 2019 10:40:20 +0000 (13:40 +0300)
committerBoris Brezillon <boris.brezillon@collabora.com>
Mon, 6 May 2019 06:15:02 +0000 (08:15 +0200)
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: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Cc: <stable@vger.kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
drivers/i3c/master.c

index 2dc628d4f1aee1b5c07593f85e7d75a6bdb3d0be..d539252eed79de843c61e65e96dfd93a6861bcaa 100644 (file)
@@ -385,8 +385,9 @@ static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
                return;
 
        ptr = bus->addrslots + (bitpos / BITS_PER_LONG);
-       *ptr &= ~(I3C_ADDR_SLOT_STATUS_MASK << (bitpos % BITS_PER_LONG));
-       *ptr |= status << (bitpos % BITS_PER_LONG);
+       *ptr &= ~((unsigned long)I3C_ADDR_SLOT_STATUS_MASK <<
+                                               (bitpos % BITS_PER_LONG));
+       *ptr |= (unsigned long)status << (bitpos % BITS_PER_LONG);
 }
 
 static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr)