Message ID | b4aaa8a9-6a8b-6d5f-1aac-718e46fbcc7d@appeartv.com (mailing list archive) |
---|---|
State | Rejected |
Headers | show |
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));
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)); -- To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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));
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(-) 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));