linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: chemical: sps30: Explicity truncate constant by masking
@ 2019-10-13  9:55 jic23
  2019-10-17 16:41 ` Tomasz Duszynski
  0 siblings, 1 reply; 3+ messages in thread
From: jic23 @ 2019-10-13  9:55 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron, Tomasz Duszynski

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

When breaking up a constant to write to two 8 bit registers
it isn't obvious to sparse that it was intentional.

CHECK   drivers/iio/chemical/sps30.c
drivers/iio/chemical/sps30.c:120:30: warning: cast truncates bits from constant value (8004 becomes 4)

So in the interests of minimising noisy warnings, let us add
a mask.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Tomasz Duszynski <tduszyns@gmail.com>
---
 drivers/iio/chemical/sps30.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
index edbb956e81e8..acb9f8ecbb3d 100644
--- a/drivers/iio/chemical/sps30.c
+++ b/drivers/iio/chemical/sps30.c
@@ -117,7 +117,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
 		break;
 	case SPS30_READ_AUTO_CLEANING_PERIOD:
 		buf[0] = SPS30_AUTO_CLEANING_PERIOD >> 8;
-		buf[1] = (u8)SPS30_AUTO_CLEANING_PERIOD;
+		buf[1] = (u8)(SPS30_AUTO_CLEANING_PERIOD & 0xff);
 		/* fall through */
 	case SPS30_READ_DATA_READY_FLAG:
 	case SPS30_READ_DATA:
-- 
2.23.0


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

* Re: [PATCH] iio: chemical: sps30: Explicity truncate constant by masking
  2019-10-13  9:55 [PATCH] iio: chemical: sps30: Explicity truncate constant by masking jic23
@ 2019-10-17 16:41 ` Tomasz Duszynski
  2019-10-18 18:52   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Tomasz Duszynski @ 2019-10-17 16:41 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Jonathan Cameron, Tomasz Duszynski

On Sun, Oct 13, 2019 at 10:55:15AM +0100, jic23@kernel.org wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> When breaking up a constant to write to two 8 bit registers
> it isn't obvious to sparse that it was intentional.
>
> CHECK   drivers/iio/chemical/sps30.c
> drivers/iio/chemical/sps30.c:120:30: warning: cast truncates bits from constant value (8004 becomes 4)
>
> So in the interests of minimising noisy warnings, let us add
> a mask.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Tomasz Duszynski <tduszyns@gmail.com>
> ---
>  drivers/iio/chemical/sps30.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
> index edbb956e81e8..acb9f8ecbb3d 100644
> --- a/drivers/iio/chemical/sps30.c
> +++ b/drivers/iio/chemical/sps30.c
> @@ -117,7 +117,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
>  		break;
>  	case SPS30_READ_AUTO_CLEANING_PERIOD:
>  		buf[0] = SPS30_AUTO_CLEANING_PERIOD >> 8;
> -		buf[1] = (u8)SPS30_AUTO_CLEANING_PERIOD;
> +		buf[1] = (u8)(SPS30_AUTO_CLEANING_PERIOD & 0xff);
>  		/* fall through */
>  	case SPS30_READ_DATA_READY_FLAG:
>  	case SPS30_READ_DATA:
> --
> 2.23.0
>

Thanks for catching this.
Acked-by: Tomasz Duszynski <tduszyns@gmail.com>

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

* Re: [PATCH] iio: chemical: sps30: Explicity truncate constant by masking
  2019-10-17 16:41 ` Tomasz Duszynski
@ 2019-10-18 18:52   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2019-10-18 18:52 UTC (permalink / raw)
  To: Tomasz Duszynski; +Cc: linux-iio, Jonathan Cameron

On Thu, 17 Oct 2019 18:41:12 +0200
Tomasz Duszynski <tduszyns@gmail.com> wrote:

> On Sun, Oct 13, 2019 at 10:55:15AM +0100, jic23@kernel.org wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > When breaking up a constant to write to two 8 bit registers
> > it isn't obvious to sparse that it was intentional.
> >
> > CHECK   drivers/iio/chemical/sps30.c
> > drivers/iio/chemical/sps30.c:120:30: warning: cast truncates bits from constant value (8004 becomes 4)
> >
> > So in the interests of minimising noisy warnings, let us add
> > a mask.
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Tomasz Duszynski <tduszyns@gmail.com>
> > ---
> >  drivers/iio/chemical/sps30.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
> > index edbb956e81e8..acb9f8ecbb3d 100644
> > --- a/drivers/iio/chemical/sps30.c
> > +++ b/drivers/iio/chemical/sps30.c
> > @@ -117,7 +117,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
> >  		break;
> >  	case SPS30_READ_AUTO_CLEANING_PERIOD:
> >  		buf[0] = SPS30_AUTO_CLEANING_PERIOD >> 8;
> > -		buf[1] = (u8)SPS30_AUTO_CLEANING_PERIOD;
> > +		buf[1] = (u8)(SPS30_AUTO_CLEANING_PERIOD & 0xff);
> >  		/* fall through */
> >  	case SPS30_READ_DATA_READY_FLAG:
> >  	case SPS30_READ_DATA:
> > --
> > 2.23.0
> >  
> 
> Thanks for catching this.
> Acked-by: Tomasz Duszynski <tduszyns@gmail.com>

Applied. Thanks,

Jonathan


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

end of thread, other threads:[~2019-10-18 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-13  9:55 [PATCH] iio: chemical: sps30: Explicity truncate constant by masking jic23
2019-10-17 16:41 ` Tomasz Duszynski
2019-10-18 18:52   ` 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).