Skip to content

Commit 621f29e

Browse files
jeremydickkartben
authored andcommitted
drivers: input: cap12xx Fix integer overflow warning
Check that calsens values are valid to prevent integer overflow Coverity-CID: 524767 Fixes #90481 Signed-off-by: Jeremy Dick <[email protected]>
1 parent da6742b commit 621f29e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/input/input_cap12xx.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ LOG_MODULE_REGISTER(cap12xx, CONFIG_INPUT_LOG_LEVEL);
4141
#define REG_CALIB_SENSITIVITY_CONFIG2 0x81
4242
#define CALSENS_BITS 2
4343
#define NUM_CALSENS_PER_REG 4
44+
#define MAX_CALSENS_GAIN 4
4445

4546
struct cap12xx_config {
4647
struct i2c_dt_spec i2c;
@@ -107,6 +108,9 @@ static int cap12xx_set_calsens(const struct i2c_dt_spec *i2c, const uint8_t *cal
107108
for (uint8_t i = 0; i < channels; i += NUM_CALSENS_PER_REG) {
108109
regval = 0;
109110
for (uint8_t j = 0; j < NUM_CALSENS_PER_REG && i + j < channels; j++) {
111+
if (calsens[i + j] > MAX_CALSENS_GAIN) {
112+
return -EINVAL;
113+
}
110114
/* Convert the enumerated sensitivity to the corresponding register value */
111115
regval |= (ilog2(calsens[i + j]) << (CALSENS_BITS * j));
112116
}

0 commit comments

Comments
 (0)