* hwmon: (adt7470) fix checking of num_temp_sensors
@ 2016-11-23 11:34 Martin Etnestad
2016-11-23 11:54 ` Martin Etnestad
2016-11-23 13:26 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Martin Etnestad @ 2016-11-23 11:34 UTC (permalink / raw)
To: linux-hwmon
The ADT7470 driver uses num_temp_sensors to check whether or not it
actually needs to read the temperature registers. However, the check
currently has a broken comparison: "num_temp_sensors >= 0" instead of
"num_temp_sensors == 0".
This causes the driver to only read the temperature registers _once_
because num_temp_sensors gets set to a non-negative number after the
check, in the same function.
Additionally, the check is currently done _after_ the measurement
sequence has been completed. The check should be done before the
measurement sequence is initiated, as it can be skipped altogether if
num_temp_sensors is 0.
This patch fixes the comparison and moves the check.
Signed-off-by: Martin Etnestad <martin.etnestad@appeartv.com>
---
drivers/hwmon/adt7470.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index f5da39a..d1f9a54 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -201,6 +201,10 @@ static int adt7470_read_temperatures(struct
i2c_client *client,
int i;
u8 cfg, pwm[4], pwm_cfg[2];
+ /* only read sensors if we have to */
+ if (data->num_temp_sensors == 0)
+ return 0;
+
/* save pwm[1-4] config register */
pwm_cfg[0] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(0));
pwm_cfg[1] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(2));
@@ -243,10 +247,6 @@ static int adt7470_read_temperatures(struct
i2c_client *client,
return -EAGAIN;
}
- /* Only count fans if we have to */
- if (data->num_temp_sensors >= 0)
- return 0;
-
for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
data->temp[i] = i2c_smbus_read_byte_data(client,
ADT7470_TEMP_REG(i));
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: hwmon: (adt7470) fix checking of num_temp_sensors
2016-11-23 11:34 hwmon: (adt7470) fix checking of num_temp_sensors Martin Etnestad
@ 2016-11-23 11:54 ` Martin Etnestad
2016-11-23 13:26 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Martin Etnestad @ 2016-11-23 11:54 UTC (permalink / raw)
To: linux-hwmon
Hi again,
Please disregard this patch!
I just saw that I had missed how adt7470_update_device() relies on
adt7470_read_temperatures().
In that context, the current code is working correctly.
And so I very humbly apologize for submitting a garbage patch.. Sorry!
-Martin
On 11/23/2016 12:34 PM, Martin Etnestad wrote:
> The ADT7470 driver uses num_temp_sensors to check whether or not it
> actually needs to read the temperature registers. However, the check
> currently has a broken comparison: "num_temp_sensors >= 0" instead of
> "num_temp_sensors == 0".
>
> This causes the driver to only read the temperature registers _once_
> because num_temp_sensors gets set to a non-negative number after the
> check, in the same function.
>
> Additionally, the check is currently done _after_ the measurement
> sequence has been completed. The check should be done before the
> measurement sequence is initiated, as it can be skipped altogether if
> num_temp_sensors is 0.
>
> This patch fixes the comparison and moves the check.
>
> Signed-off-by: Martin Etnestad <martin.etnestad@appeartv.com>
> ---
> drivers/hwmon/adt7470.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index f5da39a..d1f9a54 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -201,6 +201,10 @@ static int adt7470_read_temperatures(struct
> i2c_client *client,
> int i;
> u8 cfg, pwm[4], pwm_cfg[2];
>
> + /* only read sensors if we have to */
> + if (data->num_temp_sensors == 0)
> + return 0;
> +
> /* save pwm[1-4] config register */
> pwm_cfg[0] = i2c_smbus_read_byte_data(client,
> ADT7470_REG_PWM_CFG(0));
> pwm_cfg[1] = i2c_smbus_read_byte_data(client,
> ADT7470_REG_PWM_CFG(2));
> @@ -243,10 +247,6 @@ static int adt7470_read_temperatures(struct
> i2c_client *client,
> return -EAGAIN;
> }
>
> - /* Only count fans if we have to */
> - if (data->num_temp_sensors >= 0)
> - return 0;
> -
> for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
> data->temp[i] = i2c_smbus_read_byte_data(client,
> ADT7470_TEMP_REG(i));
--
Martin Etnestad
R&D Engineer
Email: martin.etnestad@appeartv.com
This message may contain confidential information and is meant for the right addressee only. If you are not the intended recipient you should not disseminate, distribute or copy this e-mail or take any action in reliance upon it. Please notify the sender immediately by e-mail if you have received this e-mail in error and delete it from your system.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: hwmon: (adt7470) fix checking of num_temp_sensors
2016-11-23 11:34 hwmon: (adt7470) fix checking of num_temp_sensors Martin Etnestad
2016-11-23 11:54 ` Martin Etnestad
@ 2016-11-23 13:26 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2016-11-23 13:26 UTC (permalink / raw)
To: Martin Etnestad, linux-hwmon
On 11/23/2016 03:34 AM, Martin Etnestad wrote:
> The ADT7470 driver uses num_temp_sensors to check whether or not it
> actually needs to read the temperature registers. However, the check
> currently has a broken comparison: "num_temp_sensors >= 0" instead of
> "num_temp_sensors == 0".
>
> This causes the driver to only read the temperature registers _once_
> because num_temp_sensors gets set to a non-negative number after the
> check, in the same function.
>
> Additionally, the check is currently done _after_ the measurement
> sequence has been completed. The check should be done before the
> measurement sequence is initiated, as it can be skipped altogether if
> num_temp_sensors is 0.
>
The check is there to ensure that num_temp_sensors is calculated only once.
Your change breaks that. After the initial probe, temperature sensor
values are read in adt7470_update_device(), and it is no longer necessary
to do the read from adt7470_read_temperatures().
NACK, sorry.
Guenter
> This patch fixes the comparison and moves the check.
>
> Signed-off-by: Martin Etnestad <martin.etnestad@appeartv.com>
> ---
> drivers/hwmon/adt7470.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index f5da39a..d1f9a54 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -201,6 +201,10 @@ static int adt7470_read_temperatures(struct i2c_client *client,
> int i;
> u8 cfg, pwm[4], pwm_cfg[2];
>
> + /* only read sensors if we have to */
> + if (data->num_temp_sensors == 0)
> + return 0;
> +
> /* save pwm[1-4] config register */
> pwm_cfg[0] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(0));
> pwm_cfg[1] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(2));
> @@ -243,10 +247,6 @@ static int adt7470_read_temperatures(struct i2c_client *client,
> return -EAGAIN;
> }
>
> - /* Only count fans if we have to */
> - if (data->num_temp_sensors >= 0)
> - return 0;
> -
> for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
> data->temp[i] = i2c_smbus_read_byte_data(client,
> ADT7470_TEMP_REG(i));
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-23 13:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23 11:34 hwmon: (adt7470) fix checking of num_temp_sensors Martin Etnestad
2016-11-23 11:54 ` Martin Etnestad
2016-11-23 13:26 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.