Skip to contentSkip to conversation

s3c-hwmon: Ignore invalid divider settings

lm-sensors Ben Dooks 2 participants 2 messages Nov 3, 2009

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

Avoid registering channels that have zero divider settings in them, as this will only lead to kernel OOPS from divide-by-zero when the sysfs entry is read.

---
 drivers/hwmon/s3c-hwmon.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Index: b/drivers/hwmon/s3c-hwmon.c
=================================--- a/drivers/hwmon/s3c-hwmon.c 2009-10-07 15:22:03.000000000 +0100
+++ b/drivers/hwmon/s3c-hwmon.c 2009-10-07 15:42:03.000000000 +0100
@@ -323,14 +323,21 @@ static int __devinit s3c_hwmon_probe(str
}

for (i = 0; i < ARRAY_SIZE(pdata->in); i++) {
- if (!pdata->in[i])
- continue;
+ struct s3c24xx_adc_hwmon_incfg *cfg = pdata->in[i];

- if (pdata->in[i]->mult >= 0x10000)
+ if (!cfg)
+ continue;
+
+ if (cfg->mult >= 0x10000)
dev_warn(&dev->dev,
"channel %d multiplier too large\n", i);

+ if (cfg->divider = 0) {
+ dev_err(&dev->dev, "channel %d divider zero\n", i);
+ continue;
+ }
+
ret = s3c_hwmon_create_attr(&dev->dev, pdata->in[i],
&hwmon->attrs[i], i);
if (ret) {

Signature · 8 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

Hi Ben,

Quoted 6 lines · Ben Dooks

Avoid registering channels that have zero divider settings in them, as this will only lead to kernel OOPS from divide-by-zero when the sysfs entry is read.

I do not think non-nominal signed-off-by lines have any value.

Quoted 25 lines
---
 drivers/hwmon/s3c-hwmon.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Index: b/drivers/hwmon/s3c-hwmon.c
=================================> --- a/drivers/hwmon/s3c-hwmon.c 2009-10-07 15:22:03.000000000 +0100
+++ b/drivers/hwmon/s3c-hwmon.c 2009-10-07 15:42:03.000000000 +0100

(quoted diff) +5 -3
@@ -323,14 +323,21 @@ static int __devinit s3c_hwmon_probe(str
 	}
 
 	for (i = 0; i < ARRAY_SIZE(pdata->in); i++) {
-		if (!pdata->in[i])
-			continue;
+		struct s3c24xx_adc_hwmon_incfg *cfg = pdata->in[i];
 
-		if (pdata->in[i]->mult >= 0x10000)
+		if (!cfg)
+			continue;
+		
+		if (cfg->mult >= 0x10000)
 			dev_warn(&dev->dev,
 				 "channel %d multiplier too large\n",

Review static int __devinit s3c_hwmon_probe(str · line 343

Quoted 10 lines
(quoted diff) +5 -0
 				 i);
 
+		if (cfg->divider = 0) {
+			dev_err(&dev->dev, "channel %d divider zero\n", i);
+			continue;
+		}
+
 		ret = s3c_hwmon_create_attr(&dev->dev, pdata->in[i],
 					    &hwmon->attrs[i], i);
 		if (ret) {

Patch applied, thanks.

Signature · 6 lines
Jean Delvare

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