From: Dan Carpenter <dan.carpenter@oracle.com> To: Lars-Peter Clausen <lars@metafoo.de> Cc: Michael Hennerich <Michael.Hennerich@analog.com>, Jonathan Cameron <jic23@kernel.org>, Hartmut Knaack <knaack.h@gmx.de>, Peter Meerwald <pmeerw@pmeerw.net>, linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org, Rasmus Villemoes <linux@rasmusvillemoes.dk> Subject: [patch] iio: imu: adis16400: Fix sign extension Date: Fri, 30 Jan 2015 08:30:59 +0000 [thread overview] Message-ID: <20150130083058.GD21357@mwanda> (raw) Because of C's type promotion rules, the code shifts in "((val16 & 0xFFF) << 4) >> 4;" cancel each other out and they're a no-op. The intention here was to sign-extend then 11th bit so we can use the sign_extend32() function. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> --- Please review this carefully. I'm pretty sure it's correct but this is the first time I've ever used the sign_extend32() function. diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index b70873d..ed636c9 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -414,7 +414,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, mutex_unlock(&indio_dev->mlock); if (ret) return ret; - val16 = ((val16 & 0xFFF) << 4) >> 4; + val16 = sign_extend32(val16, 11); *val = val16; return IIO_VAL_INT; case IIO_CHAN_INFO_OFFSET:
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com> To: Lars-Peter Clausen <lars@metafoo.de> Cc: Michael Hennerich <Michael.Hennerich@analog.com>, Jonathan Cameron <jic23@kernel.org>, Hartmut Knaack <knaack.h@gmx.de>, Peter Meerwald <pmeerw@pmeerw.net>, linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org, Rasmus Villemoes <linux@rasmusvillemoes.dk> Subject: [patch] iio: imu: adis16400: Fix sign extension Date: Fri, 30 Jan 2015 11:30:59 +0300 [thread overview] Message-ID: <20150130083058.GD21357@mwanda> (raw) Because of C's type promotion rules, the code shifts in "((val16 & 0xFFF) << 4) >> 4;" cancel each other out and they're a no-op. The intention here was to sign-extend then 11th bit so we can use the sign_extend32() function. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> --- Please review this carefully. I'm pretty sure it's correct but this is the first time I've ever used the sign_extend32() function. diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index b70873d..ed636c9 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -414,7 +414,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, mutex_unlock(&indio_dev->mlock); if (ret) return ret; - val16 = ((val16 & 0xFFF) << 4) >> 4; + val16 = sign_extend32(val16, 11); *val = val16; return IIO_VAL_INT; case IIO_CHAN_INFO_OFFSET:
next reply other threads:[~2015-01-30 8:30 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-01-30 8:30 Dan Carpenter [this message] 2015-01-30 8:30 ` [patch] iio: imu: adis16400: Fix sign extension Dan Carpenter 2015-01-30 8:34 ` Lars-Peter Clausen 2015-01-30 8:34 ` Lars-Peter Clausen 2015-01-30 9:22 ` Dan Carpenter 2015-01-30 9:22 ` Dan Carpenter 2015-01-30 9:31 ` Rasmus Villemoes 2015-01-30 9:31 ` Rasmus Villemoes 2015-01-30 10:23 ` Dan Carpenter 2015-01-30 10:23 ` Dan Carpenter -- strict thread matches above, loose matches on Subject: below -- 2015-01-22 23:34 [PATCH] " Rasmus Villemoes 2015-01-23 8:56 ` Lars-Peter Clausen 2015-01-26 21:07 ` Jonathan Cameron
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=20150130083058.GD21357@mwanda \ --to=dan.carpenter@oracle.com \ --cc=Michael.Hennerich@analog.com \ --cc=jic23@kernel.org \ --cc=kernel-janitors@vger.kernel.org \ --cc=knaack.h@gmx.de \ --cc=lars@metafoo.de \ --cc=linux-iio@vger.kernel.org \ --cc=linux@rasmusvillemoes.dk \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.