* [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write().
@ 2025-10-12 11:43 Ranganath V N
2025-10-12 11:57 ` Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ranganath V N @ 2025-10-12 11:43 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck
Cc: linux-hwmon, linux-kernel, skhan, david.hunter.linux, khalid,
linux-kernel-mentees, Ranganath V N
fix for the smatch errors:
drivers/hwmon/sht3x.c:606 update_interval_write() error: uninitialized symbol 'ret'.
The warning can occur when both the data->mode and mode which is
derived from get_mode_from_update_interval() are zero.
In this case, no i2c command is sent and ret remains undefined
before reaching the coman return path.
When both data->mode and mode are zero, the device remains in
single shot mode and no configuration change is required.
In such cases, it is correct to treat the operation as successful
without issuing any i2c transfer.
To address this, initialize 'ret' to 'SHT3X_CMD_LENGTH'. this makes
the no-operation path return success while keeping the existing error
to all other paths.
This change removes the smatch errors. Tested by compiling.
Signed-off-by: Ranganath V N <vnranganath.20@gmail.com>
---
drivers/hwmon/sht3x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c
index 557ad3e7752a..4b52d57eaad8 100644
--- a/drivers/hwmon/sht3x.c
+++ b/drivers/hwmon/sht3x.c
@@ -553,7 +553,7 @@ static int update_interval_read(struct device *dev)
static int update_interval_write(struct device *dev, int val)
{
u8 mode;
- int ret;
+ int ret = SHT3X_CMD_LENGTH;
const char *command;
struct sht3x_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
---
base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a
change-id: 20251012-my_driver_work-77b22c239e99
Best regards,
--
Ranganath V N <vnranganath.20@gmail.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write().
2025-10-12 11:43 [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write() Ranganath V N
@ 2025-10-12 11:57 ` Markus Elfring
2025-10-12 17:59 ` Guenter Roeck
2025-10-12 18:07 ` Guenter Roeck
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-10-12 11:57 UTC (permalink / raw)
To: Ranganath V N, linux-hwmon, Günter Röck, Jean Delvare
Cc: linux-kernel-mentees, LKML, David Hunter, khalid, Shuah Khan
…
> To address this, initialize 'ret' to 'SHT3X_CMD_LENGTH'. this makes
Make?
> the no-operation path return success while keeping the existing error
> to all other paths.
…
See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17#n94
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write().
2025-10-12 11:43 [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write() Ranganath V N
2025-10-12 11:57 ` Markus Elfring
@ 2025-10-12 17:59 ` Guenter Roeck
2025-10-12 18:07 ` Guenter Roeck
2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2025-10-12 17:59 UTC (permalink / raw)
To: Ranganath V N
Cc: Jean Delvare, linux-hwmon, linux-kernel, skhan,
david.hunter.linux, khalid, linux-kernel-mentees
On Sun, Oct 12, 2025 at 05:13:27PM +0530, Ranganath V N wrote:
> fix for the smatch errors:
> drivers/hwmon/sht3x.c:606 update_interval_write() error: uninitialized symbol 'ret'.
>
> The warning can occur when both the data->mode and mode which is
> derived from get_mode_from_update_interval() are zero.
> In this case, no i2c command is sent and ret remains undefined
> before reaching the coman return path.
>
> When both data->mode and mode are zero, the device remains in
> single shot mode and no configuration change is required.
> In such cases, it is correct to treat the operation as successful
> without issuing any i2c transfer.
>
> To address this, initialize 'ret' to 'SHT3X_CMD_LENGTH'. this makes
> the no-operation path return success while keeping the existing error
> to all other paths.
>
> This change removes the smatch errors. Tested by compiling.
>
> Signed-off-by: Ranganath V N <vnranganath.20@gmail.com>
Applied.
Guenter
> ---
> drivers/hwmon/sht3x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> ---
> base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a
> change-id: 20251012-my_driver_work-77b22c239e99
>
> Best regards,
>
> diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c
> index 557ad3e7752a..4b52d57eaad8 100644
> --- a/drivers/hwmon/sht3x.c
> +++ b/drivers/hwmon/sht3x.c
> @@ -553,7 +553,7 @@ static int update_interval_read(struct device *dev)
> static int update_interval_write(struct device *dev, int val)
> {
> u8 mode;
> - int ret;
> + int ret = SHT3X_CMD_LENGTH;
> const char *command;
> struct sht3x_data *data = dev_get_drvdata(dev);
> struct i2c_client *client = data->client;
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write().
2025-10-12 11:43 [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write() Ranganath V N
2025-10-12 11:57 ` Markus Elfring
2025-10-12 17:59 ` Guenter Roeck
@ 2025-10-12 18:07 ` Guenter Roeck
2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2025-10-12 18:07 UTC (permalink / raw)
To: Ranganath V N
Cc: Jean Delvare, linux-hwmon, linux-kernel, skhan,
david.hunter.linux, khalid, linux-kernel-mentees
On Sun, Oct 12, 2025 at 05:13:27PM +0530, Ranganath V N wrote:
> fix for the smatch errors:
> drivers/hwmon/sht3x.c:606 update_interval_write() error: uninitialized symbol 'ret'.
>
> The warning can occur when both the data->mode and mode which is
> derived from get_mode_from_update_interval() are zero.
> In this case, no i2c command is sent and ret remains undefined
> before reaching the coman return path.
>
> When both data->mode and mode are zero, the device remains in
> single shot mode and no configuration change is required.
> In such cases, it is correct to treat the operation as successful
> without issuing any i2c transfer.
Actually, in this case, the code enters
if (mode == data->mode) {
mutex_unlock(&data->data_lock);
return 0;
}
meaning the problem does not actually exist because 'ret' will be
initialized if either 'mode' or 'data->mode' is != 0. That means
the smatch report is a false positive, and this patch is not required.
Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-12 18:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-12 11:43 [PATCH] hwmon: sht3x: initialize variable 'ret' in update_interval_write() Ranganath V N
2025-10-12 11:57 ` Markus Elfring
2025-10-12 17:59 ` Guenter Roeck
2025-10-12 18:07 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).