public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (pmbus) More stringent checking of VOUT_MODE register
@ 2011-03-02  5:32 Guenter Roeck
  2011-03-07 21:44 ` Greg Schnorr
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2011-03-02  5:32 UTC (permalink / raw)
  To: Jean Delvare
  Cc: Jonathan Cameron, Randy Dunlap, Greg Schnorr, lm-sensors,
	linux-doc, linux-kernel, Guenter Roeck

Some PMBus chips do not support the VOUT_MODE register. To make matters worse,
such chips may not return an error when reading the register either, but instead
return 0xff.

Check if the register exists using pmbus_check_byte_register() before reading
its value. In addition, validate the returned value and ignore it if it is 0xff
(which is invalid).

Reported-by: Greg Schnorr <gschnorr@cisco.com>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
---
 drivers/hwmon/pmbus_core.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/pmbus_core.c b/drivers/hwmon/pmbus_core.c
index 0edab1c..b7c64ba 100644
--- a/drivers/hwmon/pmbus_core.c
+++ b/drivers/hwmon/pmbus_core.c
@@ -1426,10 +1426,11 @@ static void pmbus_find_attributes(struct i2c_client *client,
 static int pmbus_identify_common(struct i2c_client *client,
 				 struct pmbus_data *data)
 {
-	int vout_mode, exponent;
+	int vout_mode = -1, exponent;
 
-	vout_mode = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
-	if (vout_mode >= 0) {
+	if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE))
+		vout_mode = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
+	if (vout_mode >= 0 && vout_mode != 0xff) {
 		/*
 		 * Not all chips support the VOUT_MODE command,
 		 * so a failure to read it is not an error.
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwmon: (pmbus) More stringent checking of VOUT_MODE register
  2011-03-02  5:32 [PATCH] hwmon: (pmbus) More stringent checking of VOUT_MODE register Guenter Roeck
@ 2011-03-07 21:44 ` Greg Schnorr
  2011-03-07 22:11   ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Schnorr @ 2011-03-07 21:44 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Jonathan Cameron, Randy Dunlap, lm-sensors, linux-doc,
	linux-kernel

Looks good, tested and works on one such VOUT_MODE poor design...

On 3/1/11 9:32 PM, "Guenter Roeck" <guenter.roeck@ericsson.com> wrote:

> Some PMBus chips do not support the VOUT_MODE register. To make matters worse,
> such chips may not return an error when reading the register either, but
> instead
> return 0xff.
> 
> Check if the register exists using pmbus_check_byte_register() before reading
> its value. In addition, validate the returned value and ignore it if it is
> 0xff
> (which is invalid).
> 
> Reported-by: Greg Schnorr <gschnorr@cisco.com>
> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Greg Schnorr <gschnorr@cisco.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwmon: (pmbus) More stringent checking of VOUT_MODE register
  2011-03-07 21:44 ` Greg Schnorr
@ 2011-03-07 22:11   ` Guenter Roeck
  0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2011-03-07 22:11 UTC (permalink / raw)
  To: Greg Schnorr
  Cc: Jean Delvare, Jonathan Cameron, Randy Dunlap,
	lm-sensors@lm-sensors.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org

On Mon, Mar 07, 2011 at 04:44:43PM -0500, Greg Schnorr wrote:
> Looks good, tested and works on one such VOUT_MODE poor design...
> 
> On 3/1/11 9:32 PM, "Guenter Roeck" <guenter.roeck@ericsson.com> wrote:
> 
> > Some PMBus chips do not support the VOUT_MODE register. To make matters worse,
> > such chips may not return an error when reading the register either, but
> > instead
> > return 0xff.
> > 
> > Check if the register exists using pmbus_check_byte_register() before reading
> > its value. In addition, validate the returned value and ignore it if it is
> > 0xff
> > (which is invalid).
> > 
> > Reported-by: Greg Schnorr <gschnorr@cisco.com>
> > Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
> Acked-by: Greg Schnorr <gschnorr@cisco.com>
> 
Thanks!

Guenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-07 22:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-02  5:32 [PATCH] hwmon: (pmbus) More stringent checking of VOUT_MODE register Guenter Roeck
2011-03-07 21:44 ` Greg Schnorr
2011-03-07 22:11   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox