soundwire: fix sign extension when shifting buf[2] 24 places
authorColin Ian King <colin.king@canonical.com>
Mon, 8 Jan 2018 16:52:42 +0000 (22:22 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Jan 2018 16:53:20 +0000 (17:53 +0100)
The buf[2] left shift by 24 bits is promoted to int (32 bit signed)
and then signed-extended to unsigned long long. Hence if the upper
bit to buf[2] is set then all the upper bits of addr end up as 1.
Fix this by casting it to u64 before shifting it. Also replace the
unsigned long long casts to u64 casts to match the same type of
addr.

Detected by CoverityScan, CID#1463147 ("Unintended sign extension")

Fixes: d52d7a1be02c ("soundwire: Add Slave status handling helpers")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/soundwire/bus.c

index 4c345197eb55812566006ece3b5b8d22a4cb3c87..7211ecc62015693dd2c42e7bc4512c5420509af5 100644 (file)
@@ -522,8 +522,8 @@ static int sdw_program_device_num(struct sdw_bus *bus)
                 * bits to avoid truncation due to size limit.
                 */
                addr = buf[5] | (buf[4] << 8) | (buf[3] << 16) |
-                       (buf[2] << 24) | ((unsigned long long)buf[1] << 32) |
-                       ((unsigned long long)buf[0] << 40);
+                       ((u64)buf[2] << 24) | ((u64)buf[1] << 32) |
+                       ((u64)buf[0] << 40);
 
                sdw_extract_slave_id(bus, addr, &id);