diff mbox series

[1/2] hwmon: (aquacomputer_d5next) Check if temp sensors of legacy devices are connected

Message ID 20231016083559.139341-2-savicaleksa83@gmail.com (mailing list archive)
State Accepted
Headers show
Series hwmon: (aquacomputer_d5next) Add support for Aquacomputer High Flow USB and MPS Flow | expand

Commit Message

Aleksa Savic Oct. 16, 2023, 8:35 a.m. UTC
Return -ENODATA if a temp sensor of a legacy device
does not contain a reading.

Originally-from: Leonard Anderweit <leonard.anderweit@gmail.com>
Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
---
 drivers/hwmon/aquacomputer_d5next.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Guenter Roeck Oct. 25, 2023, 7:41 p.m. UTC | #1
On Mon, Oct 16, 2023 at 10:35:57AM +0200, Aleksa Savic wrote:
> Return -ENODATA if a temp sensor of a legacy device
> does not contain a reading.
> 

Why is the sensor instantiated in the first place ?
Returning -ENODATA for every reading is not desirable.
If this can happen, the is_visible function should check
for it and skip affected sensors.

Guenter

> Originally-from: Leonard Anderweit <leonard.anderweit@gmail.com>
> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
> ---
>  drivers/hwmon/aquacomputer_d5next.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c
> index 023807859be7..46ff4fd4f87d 100644
> --- a/drivers/hwmon/aquacomputer_d5next.c
> +++ b/drivers/hwmon/aquacomputer_d5next.c
> @@ -926,7 +926,10 @@ static int aqc_legacy_read(struct aqc_data *priv)
>  	for (i = 0; i < priv->num_temp_sensors; i++) {
>  		sensor_value = get_unaligned_le16(priv->buffer + priv->temp_sensor_start_offset +
>  						  i * AQC_SENSOR_SIZE);
> -		priv->temp_input[i] = sensor_value * 10;
> +		if (sensor_value == AQC_SENSOR_NA)
> +			priv->temp_input[i] = -ENODATA;
> +		else
> +			priv->temp_input[i] = sensor_value * 10;
>  	}
>  
>  	/* Special-case sensor readings */
Aleksa Savic Oct. 25, 2023, 8:04 p.m. UTC | #2
On 2023-10-25 21:41:00 GMT+02:00, Guenter Roeck wrote:
> 
> Why is the sensor instantiated in the first place ?
> Returning -ENODATA for every reading is not desirable.
> If this can happen, the is_visible function should check
> for it and skip affected sensors.
> 
> Guenter
> 

The external temp sensor(s) are hot-swappable and can be plugged
or unplugged anytime. Similar logic already exists in
aqc_raw_event() for the sensors.

Thanks,
Aleksa
diff mbox series

Patch

diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c
index 023807859be7..46ff4fd4f87d 100644
--- a/drivers/hwmon/aquacomputer_d5next.c
+++ b/drivers/hwmon/aquacomputer_d5next.c
@@ -926,7 +926,10 @@  static int aqc_legacy_read(struct aqc_data *priv)
 	for (i = 0; i < priv->num_temp_sensors; i++) {
 		sensor_value = get_unaligned_le16(priv->buffer + priv->temp_sensor_start_offset +
 						  i * AQC_SENSOR_SIZE);
-		priv->temp_input[i] = sensor_value * 10;
+		if (sensor_value == AQC_SENSOR_NA)
+			priv->temp_input[i] = -ENODATA;
+		else
+			priv->temp_input[i] = sensor_value * 10;
 	}
 
 	/* Special-case sensor readings */