drivers/iio/chemical/sps30.c:122:30: sparse: cast truncates bits from constant value (8004 becomes 4)
From: kbuild test robot
Date: Thu Mar 14 2019 - 03:15:18 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fa3d493f7a573b4e4e2538486e912093a0161c1b
commit: 62129a0849d27cc94ced832bcf9dcde283dcbe08 iio: chemical: sps30: allow changing self cleaning period
date: 8 weeks ago
reproduce:
# apt-get install sparse
git checkout 62129a0849d27cc94ced832bcf9dcde283dcbe08
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
sparse warnings: (new ones prefixed by >>)
>> drivers/iio/chemical/sps30.c:122:30: sparse: cast truncates bits from constant value (8004 becomes 4)
vim +122 drivers/iio/chemical/sps30.c
91
92 static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
93 {
94 /*
95 * Internally sensor stores measurements in a following manner:
96 *
97 * PM1: upper two bytes, crc8, lower two bytes, crc8
98 * PM2P5: upper two bytes, crc8, lower two bytes, crc8
99 * PM4: upper two bytes, crc8, lower two bytes, crc8
100 * PM10: upper two bytes, crc8, lower two bytes, crc8
101 *
102 * What follows next are number concentration measurements and
103 * typical particle size measurement which we omit.
104 */
105 u8 buf[SPS30_MAX_READ_SIZE] = { cmd >> 8, cmd };
106 int i, ret = 0;
107
108 switch (cmd) {
109 case SPS30_START_MEAS:
110 buf[2] = 0x03;
111 buf[3] = 0x00;
112 buf[4] = crc8(sps30_crc8_table, &buf[2], 2, CRC8_INIT_VALUE);
113 ret = sps30_write_then_read(state, buf, 5, NULL, 0);
114 break;
115 case SPS30_STOP_MEAS:
116 case SPS30_RESET:
117 case SPS30_START_FAN_CLEANING:
118 ret = sps30_write_then_read(state, buf, 2, NULL, 0);
119 break;
120 case SPS30_READ_AUTO_CLEANING_PERIOD:
121 buf[0] = SPS30_AUTO_CLEANING_PERIOD >> 8;
> 122 buf[1] = (u8)SPS30_AUTO_CLEANING_PERIOD;
123 case SPS30_READ_DATA_READY_FLAG:
124 case SPS30_READ_DATA:
125 case SPS30_READ_SERIAL:
126 /* every two data bytes are checksummed */
127 size += size / 2;
128 ret = sps30_write_then_read(state, buf, 2, buf, size);
129 break;
130 case SPS30_AUTO_CLEANING_PERIOD:
131 buf[2] = data[0];
132 buf[3] = data[1];
133 buf[4] = crc8(sps30_crc8_table, &buf[2], 2, CRC8_INIT_VALUE);
134 buf[5] = data[2];
135 buf[6] = data[3];
136 buf[7] = crc8(sps30_crc8_table, &buf[5], 2, CRC8_INIT_VALUE);
137 ret = sps30_write_then_read(state, buf, 8, NULL, 0);
138 break;
139 }
140
141 if (ret)
142 return ret;
143
144 /* validate received data and strip off crc bytes */
145 for (i = 0; i < size; i += 3) {
146 u8 crc = crc8(sps30_crc8_table, &buf[i], 2, CRC8_INIT_VALUE);
147
148 if (crc != buf[i + 2]) {
149 dev_err(&state->client->dev,
150 "data integrity check failed\n");
151 return -EIO;
152 }
153
154 *data++ = buf[i];
155 *data++ = buf[i + 1];
156 }
157
158 return 0;
159 }
160
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation