Skip to content

Commit 4265eb0

Browse files
keesgroeck
authored andcommitted
hwmon: (pc87360) Bounds check data->innr usage
Without visibility into the initializers for data->innr, GCC suspects using it as an index could walk off the end of the various 14-element arrays in data. Perform an explicit clamp to the array size. Silences the following warning with GCC 12+: ../drivers/hwmon/pc87360.c: In function 'pc87360_update_device': ../drivers/hwmon/pc87360.c:341:49: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 341 | data->in_max[i] = pc87360_read_value(data, | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ 342 | LD_IN, i, | ~~~~~~~~~ 343 | PC87365_REG_IN_MAX); | ~~~~~~~~~~~~~~~~~~~ ../drivers/hwmon/pc87360.c:209:12: note: at offset 255 into destination object 'in_max' of size 14 209 | u8 in_max[14]; /* Register value */ | ^~~~~~ Cc: Jim Cromie <[email protected]> Cc: Jean Delvare <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: Added comment into code clarifying context] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 8b38002 commit 4265eb0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/hwmon/pc87360.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
323323
}
324324

325325
/* Voltages */
326-
for (i = 0; i < data->innr; i++) {
326+
/*
327+
* The min() below does not have any practical meaning and is
328+
* only needed to silence a warning observed with gcc 12+.
329+
*/
330+
for (i = 0; i < min(data->innr, ARRAY_SIZE(data->in)); i++) {
327331
data->in_status[i] = pc87360_read_value(data, LD_IN, i,
328332
PC87365_REG_IN_STATUS);
329333
/* Clear bits */

0 commit comments

Comments
 (0)