Skip to contentSkip to conversation

hwmon: (twl4030-madc-hwmon) Initialize uninitialized structure elements

PATCH Superseded Guenter Roeck 2 participants 2 messages Sep 11, 2012 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/4 hwmon: (twl4030-madc-hwmon) Initialize uninitialized structure elements

twl4030_madc_conversion uses do_avg and type structure elements of twl4030_madc_request. Initialize to avoid random operation.

---
 drivers/hwmon/twl4030-madc-hwmon.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/hwmon/twl4030-madc-hwmon.c +2 -0
index 0018c7d..f8ba8b0 100644
@@ -50,6 +50,8 @@ static ssize_t madc_read(struct device *dev,
 	req.channels = (1 << attr->index);
 	req.method = TWL4030_MADC_SW2;
 	req.func_cb = NULL;
+	req.do_avg = 0;
+	req.type = TWL4030_MADC_WAIT;
 	val = twl4030_madc_conversion(&req);
 	if (val < 0)
 		return val;
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 14 lines · Guenter Roeck

twl4030_madc_conversion uses do_avg and type structure elements of twl4030_madc_request. Initialize to avoid random operation.

---
 drivers/hwmon/twl4030-madc-hwmon.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/hwmon/twl4030-madc-hwmon.c +0 -0
index 0018c7d..f8ba8b0 100644

drivers/hwmon/twl4030-madc-hwmon.c static ssize_t madc_read(struct device *dev, · line 57

Quoted 8 lines
drivers/hwmon/twl4030-madc-hwmon.c +2 -0
@@ -50,6 +50,8 @@ static ssize_t madc_read(struct device *dev,
 	req.channels = (1 << attr->index);
 	req.method = TWL4030_MADC_SW2;
 	req.func_cb = NULL;
+	req.do_avg = 0;
+	req.type = TWL4030_MADC_WAIT;
 	val = twl4030_madc_conversion(&req);
 	if (val < 0)
 		return val;

What about a structure-wide initialization at declaration time?

	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct twl4030_madc_request req = {
		.channels = 1 << attr->index,
		.method = TWL4030_MADC_SW2,
		.type = TWL4030_MADC_WAIT,
	};

IIRC the compiler will initialize all other fields to 0 in this case, which is what we want, and this also works if more fields are added in the future.

Signature · 6 lines
Jean Delvare

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