hwmon: (jc42) Don't reset hysteresis on device removal
PATCH 1/1 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.
---
Note: this would be more readable if JC42_CFG_HYST_MASK was the mask _before_ shifting instead of after shifting. Guenter, do you want me to send a separate patch doing that, or do you like it the way it is?
Alternatively we could invert the logic and only restore the JC42_CFG_SHUTDOWN bit. As this bit and the two hysteresis bits are the only ones the driver touches, this is equivalent. I don't know if there is an intent to ever have the jc42 driver touch any other bit in the configuration register. Guenter, I am leaving the decision up to you.
drivers/hwmon/jc42.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/hwmon/jc42.c +11 -3
@@ -535,9 +535,18 @@ static int jc42_remove(struct i2c_clientstruct 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 << JC42_CFG_HYST_SHIFT)) !+ (data->orig_config & + ~(JC42_CFG_HYST_MASK <<JC42_CFG_HYST_SHIFT ))) { +int config = data->orig_config; + + config &= ~(JC42_CFG_HYST_MASK <<JC42_CFG_HYST_SHIFT ); + config |= data->config | + (JC42_CFG_HYST_MASK <<JC42_CFG_HYST_SHIFT ); +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
Guenter Roeck
maintainerQuoted 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.
Signed-off-by Jean Delvare <[email protected]>Cc Guenter Roeck <[email protected]>
Good catch. Applied.
Quoted 5 lines
---
Note: this would be more readable ifJC42_CFG_HYST_MASKwas the mask _before_ shifting instead of after shifting. Guenter, do you want me to send a separate patch doing that, or do you like it the way it is?
Please send a patch.
Quoted 7 lines
Alternatively we could invert the logic and only restore the
JC42_CFG_SHUTDOWNbit. As this bit and the two hysteresis bits are the only ones the driver touches, this is equivalent. I don't know if there is an intent to ever have the jc42 driver touch any other bit in the configuration register. Guenter, I am leaving the decision up to you.
Hard to say, though looking into it seems unlikely. But who knows. I would suggest to keep it generic as you implemented.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
SGkgR3VlbnRlciwKCk9uIFRodSwgMjYgSnVsIDIwMTIgMDY6Mzc6NTAgLTA3MDAsIEd1ZW50ZXIg Um9lY2sgd3JvdGU6Cj4gT24gVGh1LCBKdWwgMjYsIDIwMTIgYXQgMDI6NTc6NDVQTSArMDIwMCwg SmVhbiBEZWx2YXJlIHdyb3RlOgo+ID4gUmVzdG9yaW5nIHRoZSBjb25maWd1cmF0aW9uIHJlZ2lz dGVyIG9uIGRldmljZSByZW1vdmFsIGhhcyB0aGUgc2lkZQo+ID4gZWZmZWN0IG9mIGFsc28gcmVz ZXR0aW5nIHRoZSBoeXN0ZXJlc2lzIHZhbHVlLiBUaGlzIGlzIGluY29uc2lzdGVudCBhcwo+ID4g dGhlIG90aGVyIGxpbWl0cyBhcmUgbm90IHJlc2V0LCBvbmx5IGh5c3RlcmVzaXMuIFNvLCBmb2xs b3dpbmcgdGhlCj4gPiBwcmluY2lwbGUgb2YgbGVhc3Qgc3VycHJpc2UsIHByZXNlcnZlIHRoZSBo eXN0ZXJlc2lzIHZhbHVlIHdoZW4KPiA+IHJlc3RvcmluZyB0aGUgY29uZmlndXJhdGlvbiByZWdp c3Rlci4KPiA+IAo+ID4gU2lnbmVkLW9mZi1ieTogSm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GhlCj4gPiBvbmx5IG9uZXMgdGhlIGRyaXZlciB0b3VjaGVzLCB0aGlzIGlzIGVxdWl2 YWxlbnQuIEkgZG9uJ3Qga25vdyBpZgo+ID4gdGhlcmUgaXMgYW4gaW50ZW50IHRvIGV2ZXIgaGF2 ZSB0aGUgamM0MiBkcml2ZXIgdG91Y2ggYW55IG90aGVyIGJpdCBpbgo+ID4gdGhlIGNvbmZpZ3Vy YXRpb24gcmVnaXN0ZXIuIEd1ZW50ZXIsIEkgYW0gbGVhdmluZyB0aGUgZGVjaXNpb24gdXAgdG8K PiA+IHlvdS4KPgo+IEhhcmQgdG8gc2F5LCB0aG91Z2ggbG9va2luZyBpbnRvIGl0IHNlZW1zIHVu bGlrZWx5LiBCdXQgd2hvIGtub3dzLiBJIHdvdWxkCj4gc3VnZ2VzdCB0byBrZWVwIGl0IGdlbmVy aWMgYXMgeW91IGltcGxlbWVudGVkLgoKRmluZSB3aXRoIG1lLgoKLS0gCkplYW4gRGVsdmFyZQoK X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29y cyBtYWlsaW5nIGxpc3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0t c2Vuc29ycy5vcmcvbWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz
Guenter Roeck
maintainerQuoted 13 lines · Jean Delvare
Hi Guenter,
Quoted 10 lines · Guenter Roeck
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.
Signed-off-by Jean Delvare <[email protected]>Cc Guenter Roeck <[email protected]>
Quoted 7 lines
Quoted 1 line
Good catch. Applied.
Doh, please drop it, the patch is buggy. I wrote | where I meant & and this hard-codes the hysteresis to -6°C at driver removal if the config register changed. I didn't notice during my testing because config doesn't change for me. Sorry for the noise.
.... and I didn't notice it wither, and had to look at the code for a while to find it. Doh as well.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors