Skip to content

Commit 9207749

Browse files
moonlight83340danieldegrasse
authored andcommitted
drivers: sensor: bma4xx: Avoid potential overflow
Coverity reports a potential integer overflow in the accel_range computation due to the use of a left shift on an int type. CID 520269: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN) Even though the register value is constrained to 0–3 by the BMA456 spec, and no real overflow occurs, an explicit cast to int64_t prevents false positives and aligns with safe coding practices. Fixes: #90517 Signed-off-by: Gaetan Perrot <[email protected]>
1 parent ad38ef7 commit 9207749

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/sensor/bosch/bma4xx/bma4xx_emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void bma4xx_emul_set_accel_data(const struct emul *target, q31_t value, int8_t s
203203
int16_t reg_val;
204204

205205
/* 0x00 -> +/-2g; 0x01 -> +/-4g; 0x02 -> +/-8g; 0x03 -> +/- 16g; */
206-
int64_t accel_range = (2 << data->regs[BMA4XX_REG_ACCEL_RANGE]);
206+
int64_t accel_range = 2LL << data->regs[BMA4XX_REG_ACCEL_RANGE];
207207

208208
unshifted = shift < 0 ? ((int64_t)value >> -shift) : ((int64_t)value << shift);
209209

0 commit comments

Comments
 (0)