* [PATCH][next] soundwire: fix sign extension when shifting buf[2] 24 places
@ 2017-12-21 23:51 Colin King
2017-12-22 12:42 ` Vinod Koul
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2017-12-21 23:51 UTC (permalink / raw)
To: Vinod Koul, Sanyog Kale, alsa-devel; +Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
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>
---
drivers/soundwire/bus.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 4c345197eb55..7211ecc62015 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -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);
--
2.14.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] soundwire: fix sign extension when shifting buf[2] 24 places
2017-12-21 23:51 [PATCH][next] soundwire: fix sign extension when shifting buf[2] 24 places Colin King
@ 2017-12-22 12:42 ` Vinod Koul
0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2017-12-22 12:42 UTC (permalink / raw)
To: Colin King; +Cc: Sanyog Kale, alsa-devel, kernel-janitors, linux-kernel
On Thu, Dec 21, 2017 at 11:51:13PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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.
Applied, thanks
>
> 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>
> ---
> drivers/soundwire/bus.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index 4c345197eb55..7211ecc62015 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -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);
>
> --
> 2.14.1
>
--
~Vinod
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-22 12:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-21 23:51 [PATCH][next] soundwire: fix sign extension when shifting buf[2] 24 places Colin King
2017-12-22 12:42 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).