hwmon: (ltc2945) Don't crash the kernel unnecessarily
Guenter Roeck
maintainerPATCH 1/1 hwmon: (ltc2945) Don't crash the kernel unnecessarily
An implementation error should not crash the kernel if it is avoidable. Replace BUG() with WARN_ONCE().
--- drivers/hwmon/ltc2945.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hwmon/ltc2945.c +3 -3
@@ -1,4 +1,4 @@ -/* +/* * Driver for Linear Technology LTC2945 I2C Power Monitor * * Copyright (c) 2014 Guenter Roeck
@@ -314,8 +314,8 @@ static ssize_t ltc2945_reset_history(struct device *dev, reg =LTC2945_MAX_ADIN_H ;break ;default : -BUG (); -break ; +WARN_ONCE (1 ,"Bad register: 0x%x\n" , reg); +return -EINVAL ; }/* Reset maximum */ ret =regmap_bulk_write (regmap, reg, buf_max, num_regs);
Signature · 7 lines
1.7.9.7 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
Quoted 19 lines · Guenter Roeck
An implementation error should not crash the kernel if it is avoidable. Replace
BUG()withWARN_ONCE().Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/ltc2945.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/hwmon/ltc2945.c +1
-1@@ -1,4 +1,4 @@ -/* +/* * Driver for Linear Technology LTC2945 I2C Power Monitor * * Copyright (c) 2014 Guenter Roeck
drivers/hwmon/ltc2945.c static ssize_t ltc2945_reset_history(struct device *dev, · line 321
Quoted 10 lines
drivers/hwmon/ltc2945.c +2
-2@@ -314,8 +314,8 @@ static ssize_t ltc2945_reset_history(struct device *dev, reg =LTC2945_MAX_ADIN_H ;break ;default : -BUG (); -break ; +WARN_ONCE (1 ,"Bad register: 0x%x\n" , reg); +return -EINVAL ; }/* Reset maximum */ ret =regmap_bulk_write (regmap, reg, buf_max, num_regs);
Agreed. -EINVAL may be confusing though, as this normally means the user input was invalid (which isn't the case here.) Maybe we can come up with a better error code. Maybe -EFAULT? Or be original and use -EBADSLT? ;)
It's purely theoretical anyway, as we both know that this piece of code is never going to be executed. TBH if it was me I would just drop this test altogether. But anyway:
Signature · 7 lines
Jean Delvare SUSE L3 Support _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 38 lines · Jean Delvare
Hi Guenter,
Quoted 19 lines · Guenter Roeck
An implementation error should not crash the kernel if it is avoidable. Replace
BUG()withWARN_ONCE().Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/ltc2945.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/hwmon/ltc2945.c +1
-1@@ -1,4 +1,4 @@ -/* +/* * Driver for Linear Technology LTC2945 I2C Power Monitor * * Copyright (c) 2014 Guenter Roeck drivers/hwmon/ltc2945.c static ssize_t ltc2945_reset_history(struct device *dev, · line 321
Quoted 10 lines
drivers/hwmon/ltc2945.c +2
-2@@ -314,8 +314,8 @@ static ssize_t ltc2945_reset_history(struct device *dev, reg =LTC2945_MAX_ADIN_H ;break ;default : -BUG (); -break ; +WARN_ONCE (1 ,"Bad register: 0x%x\n" , reg); +return -EINVAL ; }/* Reset maximum */ ret =regmap_bulk_write (regmap, reg, buf_max, num_regs);Agreed.
-EINVALmay be confusing though, as this normally means the user input was invalid (which isn't the case here.) Maybe we can come up with a better error code. Maybe-EFAULT? Or be original and use-EBADSLT? ;)
Quoted 4 lines
It's purely theoretical anyway, as we both know that this piece of code is never going to be executed. TBH if it was me I would just drop this test altogether. But anyway:
Guess I'll leave it as is ... as you said, it is theoretic anyway, at least for now. I don't want to drop the case entirely; someone might add code later on and screw it up. Also I can't just drop the default:
case without getting a gcc complaint. Sure, I could silently set the variables to some default, but that doesn't seem to be right either.
It would be nice to have something like -EIMPLEMENTATION_ERROR for such cases ...
Thanks a lot for the reviews!
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors