Skip to contentSkip to conversation

hwmon: (jc42) Don't reset hysteresis on device removal

PATCH Applied Jean Delvare 2 participants 2 messages Jul 26, 2012 – Jul 27, 2012 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 hwmon: (jc42) Don't reset hysteresis on device removal

Restoring the configuration register on device removal has the side effect of also resetting the hysteresis value. This is inconsistent as the other limits are not reset, only hysteresis. So, following the principle of least surprise, preserve the hysteresis value when restoring the configuration register.

---
Changes since v1:
* Fix |-for-& thinko.
* Use the new definition of JC42_CFG_HYST_MASK, makes the code more readable.

 drivers/hwmon/jc42.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/hwmon/jc42.c +9 -3
@@ -534,9 +534,16 @@ static int jc42_remove(struct i2c_client
 	struct jc42_data *data = i2c_get_clientdata(client);
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &jc42_group);
-	if (data->config != data->orig_config)
-		i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
-					     data->orig_config);
+
+	/* Restore original configuration except hysteresis */
+	if ((data->config & ~JC42_CFG_HYST_MASK) !+	    (data->orig_config & ~JC42_CFG_HYST_MASK)) {
+		int config;
+
+		config = (data->orig_config & ~JC42_CFG_HYST_MASK)
+		  | (data->config & JC42_CFG_HYST_MASK);
+		i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
+	}
 	return 0;
 }
 
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer Applied
#1 lore raw
Quoted 8 lines · Jean Delvare

Restoring the configuration register on device removal has the side effect of also resetting the hysteresis value. This is inconsistent as the other limits are not reset, only hysteresis. So, following the principle of least surprise, preserve the hysteresis value when restoring the configuration register.

Applied.

Thanks,
Guenter

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