Skip to contentSkip to conversation

lm80.c: reinitialize client if data is

PATCH In review Frans Meulenbroeks 2 participants 2 messages Jan 5, 2012 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 lm80.c: reinitialize client if data is

if data->valid = 0 when asking for an update reinitialize the client.
This is done for the case that the device got disconnected as without reinitialisation it will not give any sensible readings.

---

Tested with actual system and unplugging and replugging the device

 drivers/hwmon/lm80.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/hwmon/lm80.c +5 -0
index 616f470..1d86912 100644
@@ -583,6 +583,11 @@ static struct lm80_data *lm80_update_device(struct device *dev)
 
 	mutex_lock(&data->update_lock);
 
+    /* If the data is not valid it might be the device was temporarily
+       disconnected. In order to keep things running re-initialize the lm80 */
+	if (!data->valid)
+		lm80_init_client(client);
+
 	if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
 		dev_dbg(&client->dev, "Starting lm80 update\n");
 		for (i = 0; i <= 6; i++) {
Signature · 7 lines
1.7.0.4


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Re: [lm-sensors] [PATCH v2 2/2] lm80.c: reinitialize client if data

Quoted 19 lines · Frans Meulenbroeks

if data->valid = 0 when asking for an update reinitialize the client.
This is done for the case that the device got disconnected as without reinitialisation it will not give any sensible readings.

---

Tested with actual system and unplugging and replugging the device

 drivers/hwmon/lm80.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/hwmon/lm80.c +0 -0
index 616f470..1d86912 100644

drivers/hwmon/lm80.c static struct lm80_data *lm80_update_device(struct device *dev) · line 590

Quoted 8 lines
drivers/hwmon/lm80.c +5 -0
@@ -583,6 +583,11 @@ static struct lm80_data *lm80_update_device(struct device *dev)
 
 	mutex_lock(&data->update_lock);
 
+    /* If the data is not valid it might be the device was temporarily
+       disconnected. In order to keep things running re-initialize the lm80 */
+	if (!data->valid)
+		lm80_init_client(client);
+

Problem with this is that it results in double initialization for everyone, since data->valid will initially be false.

I would prefer if you add an error flag and set it if an error actually occurs, and use it to determine if you want/need to re-initialize the chip.

Also, think it would be better if you modify lm80_init_client() to return an error if chip initialization fails, and bail out if that happens. After all, it doesn't make sense to try to re-initialize the chip while is not there, or to try reading from it if chip initialization failed. So you would have something like

	if (data->error) {
		rv = lm80_init_client(client);
		if (rv)
			goto abort;
		data->error = 0;
	}

	...
abort:
	ret = ERR_PTR(rv);
	data->error = 1;
	data->valid = 0;
	...

With the added error checking, you should probably bail out in the _probe function if lm80_init_client() fails.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors