From ca90bdacf3bf6de2484b52faf5d24617d4fe8a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Fri, 24 Feb 2023 12:44:59 +0100 Subject: [PATCH] drivers: sensor: th02: Handle unsupported channels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed th02_channel_get() code to return -ENOTSUP when the channel is not supported. Fixes #55160. Signed-off-by: Benjamin Cabé --- drivers/sensor/th02/th02.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/sensor/th02/th02.c b/drivers/sensor/th02/th02.c index 311aac65c46..44c5f0c66f5 100644 --- a/drivers/sensor/th02/th02.c +++ b/drivers/sensor/th02/th02.c @@ -110,10 +110,12 @@ static int th02_channel_get(const struct device *dev, /* val = sample / 32 - 50 */ val->val1 = drv_data->t_sample / 32U - 50; val->val2 = (drv_data->t_sample % 32) * (1000000 / 32); - } else { + } else if (chan == SENSOR_CHAN_HUMIDITY) { /* val = sample / 16 -24 */ val->val1 = drv_data->rh_sample / 16U - 24; val->val2 = (drv_data->rh_sample % 16) * (1000000 / 16); + } else { + return -ENOTSUP; } return 0;