kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: iio: ade7759: fix signed extension bug on shift of a u8
@ 2017-09-13 17:02 Colin King
  2017-09-30 20:14 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2017-09-13 17:02 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman,
	linux-iio, devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The current shift of st->rx[2] left shifts a u8 24 bits left,
promotes the integer to a an int and then to a unsigned u64. If
the top bit of st->rx[2] is set then we end up with all the upper
bits being set to 1. Fix this by casting st->rx[2] to a u64 before
the 24 bit left shift.

Detected by CoverityScan CID#144940 ("Unintended sign extension")

Fixes: 2919fa54ef64 ("staging: iio: meter: new driver for ADE7759 devices")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/iio/meter/ade7759.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
index 1691760339da..02573c517d9d 100644
--- a/drivers/staging/iio/meter/ade7759.c
+++ b/drivers/staging/iio/meter/ade7759.c
@@ -172,7 +172,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
 				reg_address);
 		goto error_ret;
 	}
-	*val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
+	*val = ((u64)st->rx[1] << 32) | ((u64)st->rx[2] << 24) |
 		(st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
 
 error_ret:
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: iio: ade7759: fix signed extension bug on shift of a u8
  2017-09-13 17:02 [PATCH] staging: iio: ade7759: fix signed extension bug on shift of a u8 Colin King
@ 2017-09-30 20:14 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2017-09-30 20:14 UTC (permalink / raw)
  To: Colin King
  Cc: Lars-Peter Clausen, Michael Hennerich, Hartmut Knaack,
	Peter Meerwald-Stadler, Greg Kroah-Hartman, linux-iio, devel,
	kernel-janitors, linux-kernel

On Wed, 13 Sep 2017 18:02:02 +0100
Colin King <colin.king@canonical.com> wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> The current shift of st->rx[2] left shifts a u8 24 bits left,
> promotes the integer to a an int and then to a unsigned u64. If
> the top bit of st->rx[2] is set then we end up with all the upper
> bits being set to 1. Fix this by casting st->rx[2] to a u64 before
> the 24 bit left shift.
> 
> Detected by CoverityScan CID#144940 ("Unintended sign extension")
> 
> Fixes: 2919fa54ef64 ("staging: iio: meter: new driver for ADE7759 devices")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/meter/ade7759.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
> index 1691760339da..02573c517d9d 100644
> --- a/drivers/staging/iio/meter/ade7759.c
> +++ b/drivers/staging/iio/meter/ade7759.c
> @@ -172,7 +172,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
>  				reg_address);
>  		goto error_ret;
>  	}
> -	*val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
> +	*val = ((u64)st->rx[1] << 32) | ((u64)st->rx[2] << 24) |
>  		(st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
>  
>  error_ret:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-30 20:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-13 17:02 [PATCH] staging: iio: ade7759: fix signed extension bug on shift of a u8 Colin King
2017-09-30 20:14 ` Jonathan Cameron

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).