Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (occ) Fix poll rate limiting

The poll rate limiter time was initialized at zero. This breaks the
comparison in time_after if jiffies is large. Switch to storing the
next update time rather than the previous time, and initialize the
time when the device is probed.

Fixes: c10e753d43eb ("hwmon (occ): Add sensor types and versions")
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20210429151336.18980-1-eajames@linux.ibm.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Eddie James and committed by
Guenter Roeck
5216dff2 726c945a

+4 -3
+3 -2
drivers/hwmon/occ/common.c
··· 217 217 return rc; 218 218 219 219 /* limit the maximum rate of polling the OCC */ 220 - if (time_after(jiffies, occ->last_update + OCC_UPDATE_FREQUENCY)) { 220 + if (time_after(jiffies, occ->next_update)) { 221 221 rc = occ_poll(occ); 222 - occ->last_update = jiffies; 222 + occ->next_update = jiffies + OCC_UPDATE_FREQUENCY; 223 223 } else { 224 224 rc = occ->last_error; 225 225 } ··· 1165 1165 return rc; 1166 1166 } 1167 1167 1168 + occ->next_update = jiffies + OCC_UPDATE_FREQUENCY; 1168 1169 occ_parse_poll_response(occ); 1169 1170 1170 1171 rc = occ_setup_sensor_attrs(occ);
+1 -1
drivers/hwmon/occ/common.h
··· 99 99 u8 poll_cmd_data; /* to perform OCC poll command */ 100 100 int (*send_cmd)(struct occ *occ, u8 *cmd); 101 101 102 - unsigned long last_update; 102 + unsigned long next_update; 103 103 struct mutex lock; /* lock OCC access */ 104 104 105 105 struct device *hwmon;