hwmon: (occ) Fix poll rate limiting
PATCH 1/1 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 <[email protected]>
--- drivers/hwmon/occ/common.c | 5 +++-- drivers/hwmon/occ/common.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/hwmon/occ/common.c +3 -2
@@ -217,9 +217,9 @@ int occ_update_response(struct occ *occ)return rc;/* limit the maximum rate of polling the OCC */ -if (time_after (jiffies, occ->last_update +OCC_UPDATE_FREQUENCY )) { +if (time_after (jiffies, occ->next_update)) { rc =occ_poll (occ); - occ->last_update = jiffies; + occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ; }else { rc = occ->last_error; }
@@ -1165,6 +1165,7 @@ int occ_setup(struct occ *occ, const char *name)return rc; } + occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ;occ_parse_poll_response (occ); rc =occ_setup_sensor_attrs (occ);
drivers/hwmon/occ/common.h +1 -1
@@ -99,7 +99,7 @@ struct occ {u8 poll_cmd_data;/* to perform OCC poll command */ int (*send_cmd)(struct occ *occ,u8 *cmd); -unsigned long last_update; +unsigned long next_update;struct mutex lock;/* lock OCC access */ struct device *hwmon;
Signature · 1 line
2.27.0
Quoted 7 lines · Eddie James
The poll rate limiter time was initialized at zero. This breaks the comparison in
time_afterif 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 <[email protected]>
Applied.
Thanks,
Guenter
Quoted 42 lines
--- drivers/hwmon/occ/common.c | 5 +++-- drivers/hwmon/occ/common.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)drivers/hwmon/occ/common.c +3
-2@@ -217,9 +217,9 @@ int occ_update_response(struct occ *occ)return rc;/* limit the maximum rate of polling the OCC */ -if (time_after (jiffies, occ->last_update +OCC_UPDATE_FREQUENCY )) { +if (time_after (jiffies, occ->next_update)) { rc =occ_poll (occ); - occ->last_update = jiffies; + occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ; }else { rc = occ->last_error; }@@ -1165,6 +1165,7 @@ int occ_setup(struct occ *occ, const char *name)return rc; } + occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ;occ_parse_poll_response (occ); rc =occ_setup_sensor_attrs (occ);drivers/hwmon/occ/common.h +1
-1@@ -99,7 +99,7 @@ struct occ {u8 poll_cmd_data;/* to perform OCC poll command */ int (*send_cmd)(struct occ *occ,u8 *cmd); -unsigned long last_update; +unsigned long next_update;struct mutex lock;/* lock OCC access */ struct device *hwmon;