]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.0.15/i3c-fix-a-shift-wrap-bug-in-i3c_bus_set_addr_slot_status.patch
Linux 5.0.15
[thirdparty/kernel/stable-queue.git] / releases / 5.0.15 / i3c-fix-a-shift-wrap-bug-in-i3c_bus_set_addr_slot_status.patch
1 From 476c7e1d34f2a03b1aa5a924c50703053fe5f77c Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Tue, 23 Apr 2019 13:40:20 +0300
4 Subject: i3c: Fix a shift wrap bug in i3c_bus_set_addr_slot_status()
5
6 From: Dan Carpenter <dan.carpenter@oracle.com>
7
8 commit 476c7e1d34f2a03b1aa5a924c50703053fe5f77c upstream.
9
10 The problem here is that addr can be I3C_BROADCAST_ADDR (126). That
11 means we're shifting by (126 * 2) % 64 which is 60. The
12 I3C_ADDR_SLOT_STATUS_MASK is an enum which is an unsigned int in GCC
13 so shifts greater than 31 are undefined.
14
15 Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
16 Cc: <stable@vger.kernel.org>
17 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
18 Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20
21 ---
22 drivers/i3c/master.c | 5 +++--
23 1 file changed, 3 insertions(+), 2 deletions(-)
24
25 --- a/drivers/i3c/master.c
26 +++ b/drivers/i3c/master.c
27 @@ -385,8 +385,9 @@ static void i3c_bus_set_addr_slot_status
28 return;
29
30 ptr = bus->addrslots + (bitpos / BITS_PER_LONG);
31 - *ptr &= ~(I3C_ADDR_SLOT_STATUS_MASK << (bitpos % BITS_PER_LONG));
32 - *ptr |= status << (bitpos % BITS_PER_LONG);
33 + *ptr &= ~((unsigned long)I3C_ADDR_SLOT_STATUS_MASK <<
34 + (bitpos % BITS_PER_LONG));
35 + *ptr |= (unsigned long)status << (bitpos % BITS_PER_LONG);
36 }
37
38 static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr)