Skip to contentSkip to conversation

hwmon (occ): Fix an infinite for loop issue

PATCH New Lei YU 1 participant 1 message Mar 21, 2018 Hardware monitoring

lore
Share & tools
lore

Lei YU

author
#0 lore raw

PATCH 1/1 hwmon (occ): Fix an infinite for loop issue

The for loop without ++i cause either infinite loop or random memory access issues, e.g. unable to handle kernel NULL or kernel oops in snprintf.

Fix it by adding ++i in the for loop.

---
 drivers/hwmon/occ/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/occ/common.c +1 -1
index d0b2a29..88c3291 100644
@@ -916,7 +916,7 @@ static int occ_setup_sensor_attrs(struct occ *occ)
 		/* Special case for many-attribute power sensor. Split it into
 		 * a sensor number per power type, emulating several sensors.
 		 */
-		for (i = 0; i < sensors->power.num_sensors; ) {
+		for (i = 0; i < sensors->power.num_sensors; ++i) {
 			s = (i * 4) + 1;
 
 			snprintf(attr->name, sizeof(attr->name),
Signature · 1 line
2.7.4