Skip to contentSkip to conversation

iio: chemical: sps30: Explicity truncate constant by masking

PATCH In review [email protected] 2 participants 3 messages Oct 13, 2019 – Oct 18, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 iio: chemical: sps30: Explicity truncate constant by masking

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/chemical/sps30.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30.c +1 -1
index edbb956e81e8..acb9f8ecbb3d 100644
@@ -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:
Signature · 1 line
2.23.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 31 lines · On Sun, Oct 13, 2019 at 10:55:15AM +0100, [email protected] wrote:

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/chemical/sps30.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30.c +1 -2
index edbb956e81e8..acb9f8ecbb3d 100644
@@ -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:
--
Quoted 2 lines

2.23.0

Thanks for catching this.

author maintainer Applied
#2 lore raw
Quoted 36 lines · On Thu, 17 Oct 2019 18:41:12 +0200 Tomasz Duszynski <[email protected]> wrote:
Quoted 31 lines · On Sun, Oct 13, 2019 at 10:55:15AM +0100, [email protected] wrote:

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/chemical/sps30.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30.c +1 -2
index edbb956e81e8..acb9f8ecbb3d 100644
@@ -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:
--
Quoted 2 lines

2.23.0

Thanks for catching this.

Quoted 1 line

Applied. Thanks,

Jonathan