public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Colin King <colin.king@canonical.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-iio@vger.kernel.org, devel@driverdev.osuosl.org,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: iio: ade7759: fix signed extension bug on shift of a u8
Date: Sat, 30 Sep 2017 20:14:46 +0000	[thread overview]
Message-ID: <20170930211446.07222690@archlinux> (raw)
In-Reply-To: <20170913170202.8029-1-colin.king@canonical.com>

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:


      reply	other threads:[~2017-09-30 20:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170930211446.07222690@archlinux \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=colin.king@canonical.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox