Skip to contentSkip to conversation

hwmon: (pmbus/ltc2978) Fix peak attribute inizialization and clearing

PATCH In review Guenter Roeck 2 participants 9 messages Feb 23, 2013 – Feb 27, 2013 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 3/7 hwmon: (pmbus/ltc2978) Fix peak attribute inizialization and clearing

Peak attributes were not initialized and cleared correctly.

---
Candidate for -stable.

 drivers/hwmon/pmbus/ltc2978.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/hwmon/pmbus/ltc2978.c +14 -10
index 9652a2c..eec294a 100644
@@ -248,26 +248,26 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 
 	switch (reg) {
 	case PMBUS_VIRT_RESET_IOUT_HISTORY:
-		data->iout_max[page] = 0x7fff;
+		data->iout_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_TEMP2_HISTORY:
-		data->temp2_max[page] = 0x7fff;
+		data->temp2_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
 		data->vout_min[page] = 0xffff;
-		data->vout_max[page] = 0;
+		data->vout_max[page] = 0x0000;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VIN_HISTORY:
 		data->vin_min = 0x7bff;
-		data->vin_max = 0;
+		data->vin_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
-		data->temp_min = 0x7bff;
-		data->temp_max = 0x7fff;
+		data->temp_min = 0xfbff;
+		data->temp_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	default:
@@ -321,10 +321,10 @@ static int ltc2978_probe(struct i2c_client *client,
 	info = &data->info;
 	info->write_word_data = ltc2978_write_word_data;
 
-	data->vout_min[0] = 0xffff;
 	data->vin_min = 0x7bff;
+	data->vin_max = 0x7c00;
 	data->temp_min = 0x7bff;
-	data->temp_max = 0x7fff;
+	data->temp_max = 0x7c00;
 
 	switch (id->driver_data) {
 	case ltc2978:
@@ -336,7 +336,6 @@ static int ltc2978_probe(struct i2c_client *client,
 		for (i = 1; i < 8; i++) {
 			info->func[i] = PMBUS_HAVE_VOUT
 			  | PMBUS_HAVE_STATUS_VOUT;
-			data->vout_min[i] = 0xffff;
 		}
 		break;
 	case ltc3880:
@@ -352,11 +351,16 @@ static int ltc2978_probe(struct i2c_client *client,
 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT
 		  | PMBUS_HAVE_POUT
 		  | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
-		data->vout_min[1] = 0xffff;
+		data->temp2_max[0] = 0x7c00;
+		data->temp2_max[1] = 0x7c00;
 		break;
 	default:
 		return -ENODEV;
 	}
+	for (i = 0; i < info->pages; i++) {
+		data->vout_min[i] = 0xffff;
+		data->iout_max[i] = 0x7c00;
+	}
 
 	return pmbus_do_probe(client, id, info);
 }
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

Hi Guenter,

Quoted 5 lines · Guenter Roeck

Peak attributes were not initialized and cleared correctly.

---
Candidate for -stable.

Agreed, once it is correct...

Quoted 15 lines
 drivers/hwmon/pmbus/ltc2978.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/hwmon/pmbus/ltc2978.c +1 -1
index 9652a2c..eec294a 100644
@@ -248,26 +248,26 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 
 	switch (reg) {
 	case PMBUS_VIRT_RESET_IOUT_HISTORY:
-		data->iout_max[page] = 0x7fff;
+		data->iout_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_write_word_data(struct i2c_client *client, int page, · line 260

Quoted 10 lines
drivers/hwmon/pmbus/ltc2978.c +2 -2
 		break;
 	case PMBUS_VIRT_RESET_TEMP2_HISTORY:
-		data->temp2_max[page] = 0x7fff;
+		data->temp2_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
 		data->vout_min[page] = 0xffff;
-		data->vout_max[page] = 0;
+		data->vout_max[page] = 0x0000;

If the patch is intended for stable you may want to avoid this kind of avoidable change.

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_write_word_data(struct i2c_client *client, int page, · line 269

Quoted 12 lines
drivers/hwmon/pmbus/ltc2978.c +2 -3
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VIN_HISTORY:
 		data->vin_min = 0x7bff;
-		data->vin_max = 0;
+		data->vin_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
-		data->temp_min = 0x7bff;
-		data->temp_max = 0x7fff;
+		data->temp_min = 0xfbff;

This looks wrong, 0x7bff was correct as far as I can see? And that's what you still use during probe, BTW.

Quoted 26 lines
drivers/hwmon/pmbus/ltc2978.c +3 -3
+		data->temp_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	default:
@@ -321,10 +321,10 @@ static int ltc2978_probe(struct i2c_client *client,
 	info = &data->info;
 	info->write_word_data = ltc2978_write_word_data;
 
-	data->vout_min[0] = 0xffff;
 	data->vin_min = 0x7bff;
+	data->vin_max = 0x7c00;
 	data->temp_min = 0x7bff;
-	data->temp_max = 0x7fff;
+	data->temp_max = 0x7c00;
 
 	switch (id->driver_data) {
 	case ltc2978:
@@ -336,7 +336,6 @@ static int ltc2978_probe(struct i2c_client *client,
 		for (i = 1; i < 8; i++) {
 			info->func[i] = PMBUS_HAVE_VOUT
 			  | PMBUS_HAVE_STATUS_VOUT;
-			data->vout_min[i] = 0xffff;
 		}
 		break;
 	case ltc3880:

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 355

Quoted 6 lines
drivers/hwmon/pmbus/ltc2978.c +2 -1
@@ -352,11 +351,16 @@ static int ltc2978_probe(struct i2c_client *client,
 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT
 		  | PMBUS_HAVE_POUT
 		  | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
-		data->vout_min[1] = 0xffff;
+		data->temp2_max[0] = 0x7c00;
+		data->temp2_max[1] = 0x7c00;

Unrelated to this patch, but how is data->temp2_max[1] is supposed to be used when only page 0 has PMBUS_HAVE_TEMP2 defined?

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 362

Quoted 7 lines
drivers/hwmon/pmbus/ltc2978.c +3 -0
 		break;
 	default:
 		return -ENODEV;
 	}
+	for (i = 0; i < info->pages; i++) {
+		data->vout_min[i] = 0xffff;
+		data->iout_max[i] = 0x7c00;

Looks very wrong, data->iout_max[] contains 2 elements and info->pages could be 8. Only the LTC3880 needs data->iout_max[] anyway, right?

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 363

Quoted 1 line
drivers/hwmon/pmbus/ltc2978.c +1 -0
+	}

IMHO it would make more sense to have this grouped with the other similar initializations. Or left where it was originally...

Quoted 3 lines
drivers/hwmon/pmbus/ltc2978.c +0 -0
 	return pmbus_do_probe(client, id, info);
 }
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Guenter Roeck

And one more thing, typo in the subject: inizialization -> initialization

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#3 lore raw
In reply to Guenter Roeck
Quoted 11 lines · Jean Delvare

Hi Guenter,

Quoted 5 lines · Guenter Roeck

Peak attributes were not initialized and cleared correctly.

---
Candidate for -stable.

Agreed, once it is correct...

Maybe I'll even manage to get it right at some point in the far distant future ...

Quoted 29 lines
Quoted 15 lines
 drivers/hwmon/pmbus/ltc2978.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/hwmon/pmbus/ltc2978.c +1 -1
index 9652a2c..eec294a 100644
@@ -248,26 +248,26 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 
 	switch (reg) {
 	case PMBUS_VIRT_RESET_IOUT_HISTORY:
-		data->iout_max[page] = 0x7fff;
+		data->iout_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_write_word_data(struct i2c_client *client, int page, · line 260

Quoted 10 lines
drivers/hwmon/pmbus/ltc2978.c +2 -2
 		break;
 	case PMBUS_VIRT_RESET_TEMP2_HISTORY:
-		data->temp2_max[page] = 0x7fff;
+		data->temp2_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
 		data->vout_min[page] = 0xffff;
-		data->vout_max[page] = 0;
+		data->vout_max[page] = 0x0000;

If the patch is intended for stable you may want to avoid this kind of avoidable change.

Quoted 16 lines

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_write_word_data(struct i2c_client *client, int page, · line 269

Quoted 12 lines
drivers/hwmon/pmbus/ltc2978.c +2 -3
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VIN_HISTORY:
 		data->vin_min = 0x7bff;
-		data->vin_max = 0;
+		data->vin_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
-		data->temp_min = 0x7bff;
-		data->temp_max = 0x7fff;
+		data->temp_min = 0xfbff;

This looks wrong, 0x7bff was correct as far as I can see? And that's what you still use during probe, BTW.

No idea what I am doing. Typo :(.

Quoted 27 lines
Quoted 27 lines
drivers/hwmon/pmbus/ltc2978.c +3 -3
+		data->temp_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	default:
@@ -321,10 +321,10 @@ static int ltc2978_probe(struct i2c_client *client,
 	info = &data->info;
 	info->write_word_data = ltc2978_write_word_data;
 
-	data->vout_min[0] = 0xffff;
 	data->vin_min = 0x7bff;
+	data->vin_max = 0x7c00;
 	data->temp_min = 0x7bff;
-	data->temp_max = 0x7fff;
+	data->temp_max = 0x7c00;
 
 	switch (id->driver_data) {
 	case ltc2978:
@@ -336,7 +336,6 @@ static int ltc2978_probe(struct i2c_client *client,
 		for (i = 1; i < 8; i++) {
 			info->func[i] = PMBUS_HAVE_VOUT
 			  | PMBUS_HAVE_STATUS_VOUT;
-			data->vout_min[i] = 0xffff;
 		}
 		break;
 	case ltc3880:
@@ -352,11 +351,16 @@ static int ltc2978_probe(struct i2c_client *client,
 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT
Quoted 9 lines

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 355

Quoted 5 lines
drivers/hwmon/pmbus/ltc2978.c +2 -1
 		  | PMBUS_HAVE_POUT
 		  | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
-		data->vout_min[1] = 0xffff;
+		data->temp2_max[0] = 0x7c00;
+		data->temp2_max[1] = 0x7c00;

Unrelated to this patch, but how is data->temp2_max[1] is supposed to be used when only page 0 has PMBUS_HAVE_TEMP2 defined?

And why is it an array in the first place ? Yes, I know. That was removed in one of the subsequent patches, but I might as well do it in this one.

Quoted 11 lines

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 362

Quoted 7 lines
drivers/hwmon/pmbus/ltc2978.c +3 -0
 		break;
 	default:
 		return -ENODEV;
 	}
+	for (i = 0; i < info->pages; i++) {
+		data->vout_min[i] = 0xffff;
+		data->iout_max[i] = 0x7c00;

Looks very wrong, data->iout_max[] contains 2 elements and info->pages could be 8. Only the LTC3880 needs data->iout_max[] anyway, right?

Quoted 5 lines

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 363

Quoted 1 line
drivers/hwmon/pmbus/ltc2978.c +1 -0
+	}

IMHO it would make more sense to have this grouped with the other similar initializations. Or left where it was originally...

info->pages is only known here, so I would have to use the maximum number of pages as loop terminator if I move it up.

Thanks,
Guenter

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

author maintainer
#4 lore raw
In reply to Guenter Roeck

Subject: [PATCH v2 3/7] hwmon: (pmbus/ltc2978) Fix peak attribute handling

Peak attributes were not initialized and cleared correctly. Also, temp2_max is only supported on page 0 and thus does not need to be an array.

---
Candidate for -stable.

v2: Fix still wrong initializations.
temp2_max is only supported/used on page 0 and does not have to be an array.

 drivers/hwmon/pmbus/ltc2978.c |   28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/hwmon/pmbus/ltc2978.c +15 -13
index 9652a2c..cc29a7e 100644
@@ -62,7 +62,7 @@ struct ltc2978_data {
 	int temp_min, temp_max;
 	int vout_min[8], vout_max[8];
 	int iout_max[2];
-	int temp2_max[2];
+	int temp2_max;
 	struct pmbus_driver_info info;
 };
 
@@ -204,10 +204,9 @@ static int ltc3880_read_word_data(struct i2c_client *client, int page, int reg)
 		ret = pmbus_read_word_data(client, page,
 					   LTC3880_MFR_TEMPERATURE2_PEAK);
 		if (ret >= 0) {
-			if (lin11_to_val(ret)
-			    > lin11_to_val(data->temp2_max[page]))
-				data->temp2_max[page] = ret;
-			ret = data->temp2_max[page];
+			if (lin11_to_val(ret) > lin11_to_val(data->temp2_max))
+				data->temp2_max = ret;
+			ret = data->temp2_max;
 		}
 		break;
 	case PMBUS_VIRT_READ_VIN_MIN:
@@ -248,11 +247,11 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 
 	switch (reg) {
 	case PMBUS_VIRT_RESET_IOUT_HISTORY:
-		data->iout_max[page] = 0x7fff;
+		data->iout_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_TEMP2_HISTORY:
-		data->temp2_max[page] = 0x7fff;
+		data->temp2_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
@@ -262,12 +261,12 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 		break;
 	case PMBUS_VIRT_RESET_VIN_HISTORY:
 		data->vin_min = 0x7bff;
-		data->vin_max = 0;
+		data->vin_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
 		data->temp_min = 0x7bff;
-		data->temp_max = 0x7fff;
+		data->temp_max = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	default:
@@ -321,10 +320,11 @@ static int ltc2978_probe(struct i2c_client *client,
 	info = &data->info;
 	info->write_word_data = ltc2978_write_word_data;
 
-	data->vout_min[0] = 0xffff;
 	data->vin_min = 0x7bff;
+	data->vin_max = 0x7c00;
 	data->temp_min = 0x7bff;
-	data->temp_max = 0x7fff;
+	data->temp_max = 0x7c00;
+	data->temp2_max = 0x7c00;
 
 	switch (id->driver_data) {
 	case ltc2978:
@@ -336,7 +336,6 @@ static int ltc2978_probe(struct i2c_client *client,
 		for (i = 1; i < 8; i++) {
 			info->func[i] = PMBUS_HAVE_VOUT
 			  | PMBUS_HAVE_STATUS_VOUT;
-			data->vout_min[i] = 0xffff;
 		}
 		break;
 	case ltc3880:
@@ -352,11 +351,14 @@ static int ltc2978_probe(struct i2c_client *client,
 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT
 		  | PMBUS_HAVE_POUT
 		  | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
-		data->vout_min[1] = 0xffff;
+		data->iout_max[0] = 0x7c00;
+		data->iout_max[1] = 0x7c00;
 		break;
 	default:
 		return -ENODEV;
 	}
+	for (i = 0; i < info->pages; i++)
+		data->vout_min[i] = 0xffff;
 
 	return pmbus_do_probe(client, id, info);
 }
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#5 lore raw
In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck
Quoted 3 lines · Jean Delvare

IMHO it would make more sense to have this grouped with the other similar initializations. Or left where it was originally...

info->pages is only known here, so I would have to use the maximum number of pages as loop terminator if I move it up.

Oops, you're right, sorry for missing this. I should have guessed there was a reason.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 3/7
#6 lore raw
In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

Subject: [PATCH v2 3/7] hwmon: (pmbus/ltc2978) Fix peak attribute handling

Peak attributes were not initialized and cleared correctly. Also, temp2_max is only supported on page 0 and thus does not need to be an array.

Doing both in the same patch will make it harder to get it in stable. The second change is clearly a clean up not a bug fix.

But other than this it looks good:

Quoted 9 lines

---
Candidate for -stable.

v2: Fix still wrong initializations.
temp2_max is only supported/used on page 0 and does not have to be an array.

 drivers/hwmon/pmbus/ltc2978.c |   28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#7 lore raw
In reply to Guenter Roeck
Quoted 1 line · Jean Delvare

But other than this it looks good:

... except for the remaining typo in the subject line, of course ;)

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#8 lore raw
In reply to Guenter Roeck
Quoted 5 lines · Jean Delvare
Quoted 1 line · Jean Delvare

But other than this it looks good:

... except for the remaining typo in the subject line, of course ;)

Oh, I 'solved' that one by replacing the subject with "Fix peak attribute handling". Only my attempt to send v2 as response to v1 went wrong, and the new headline ended up embedded in the e-mail instead of showing up as new subject.

Thanks,
Guenter

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