Commit 9207749e authored by Gaetan Perrot's avatar Gaetan Perrot Committed by Daniel DeGrasse
Browse files

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: default avatarGaetan Perrot <gaetan.perrot@spacecubics.com>
parent ad38ef73
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ void bma4xx_emul_set_accel_data(const struct emul *target, q31_t value, int8_t s
	int16_t reg_val;

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

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