The hwmon chip is configured either via sysfs or by an earlier boot stage (e.g. bootloader/bios). In the sysfs case we already store the configuration values before it's written to the device. Reading in the configuration only needs to be done once at probe time to cover the second case. Signed-off-by: Chris Packham <chris.packham@xxxxxxxxxxxxxxxxxxx> --- This doesn't resolve my ongoing i2c issues[0] but avoiding unnecessary i2c reads will help a bit (it'll certainly avoid errors where the threshold spontaneously changes). [0] - https://lore.kernel.org/lkml/8e0a88ba-01e9-9bc1-c78b-20f26ce27d12@xxxxxxxxxxxxxxxxxxx/ drivers/hwmon/adm9240.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index cc3e0184e720..7e1258b20b35 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c @@ -128,7 +128,6 @@ struct adm9240_data { struct mutex update_lock; char valid; unsigned long last_updated_measure; - unsigned long last_updated_config; u8 in[6]; /* ro in0_input */ u8 in_max[6]; /* rw in0_max */ @@ -282,21 +281,11 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) return ERR_PTR(err); } data->last_updated_measure = jiffies; - } - - /* minimum config reading cycle: 300 seconds */ - if (time_after(jiffies, data->last_updated_config + (HZ * 300)) - || !data->valid) { - err = adm9240_update_config(data); - if (err < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - return ERR_PTR(err); - } - data->last_updated_config = jiffies; data->valid = 1; } + mutex_unlock(&data->update_lock); + return data; } @@ -855,7 +844,15 @@ static int adm9240_probe(struct i2c_client *new_client) new_client->name, data, adm9240_groups); - return PTR_ERR_OR_ZERO(hwmon_dev); + if (IS_ERR(hwmon_dev)) + return PTR_ERR(hwmon_dev); + + /* pull in configuration from an earlier boot stage */ + err = adm9240_update_config(data); + if (err < 0) + return err; + + return 0; } static const struct i2c_device_id adm9240_id[] = { -- 2.30.1