public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] Input: mcs-touchkey - Fix uninitialized use of error in mcs_touchkey_probe()
@ 2023-07-25 15:37 Nathan Chancellor
  2023-07-25 16:54 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2023-07-25 15:37 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: ndesaulniers, trix, frank.li, linux-input, llvm, patches,
	Nathan Chancellor

Clang warns (or errors with CONFIG_WERROR=y):

  drivers/input/keyboard/mcs_touchkey.c:149:49: error: variable 'error' is uninitialized when used here [-Werror,-Wuninitialized]
    149 |                 dev_err(&client->dev, "i2c read error[%d]\n", error);
        |                                                               ^~~~~
  include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
    144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
        |                                                                        ^~~~~~~~~~~
  include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
    110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
        |                                     ^~~~~~~~~~~
  drivers/input/keyboard/mcs_touchkey.c:110:11: note: initialize the variable 'error' to silence this warning
    110 |         int error;
        |                  ^
        |                   = 0
  1 error generated.

A refactoring updated the error handling in this block but did not
update the dev_err() call to use fw_ver instead of error. Do so now to
fix the warning and avoid printing uninitialized memory.

Closes: https://github.com/ClangBuiltLinux/linux/issues/1893
Fixes: e175eae16c1b ("Input: mcs-touchkey - convert to use devm_* api")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/input/keyboard/mcs_touchkey.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index f25e2b20e271..2410f676c7f9 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -146,7 +146,7 @@ static int mcs_touchkey_probe(struct i2c_client *client)
 
 	fw_ver = i2c_smbus_read_byte_data(client, fw_reg);
 	if (fw_ver < 0) {
-		dev_err(&client->dev, "i2c read error[%d]\n", error);
+		dev_err(&client->dev, "i2c read error[%d]\n", fw_ver);
 		return fw_ver;
 	}
 	dev_info(&client->dev, "Firmware version: %d\n", fw_ver);

---
base-commit: 447c09544275663e1082f796b26c7959915c922a
change-id: 20230725-mcs_touchkey-fix-wuninitialized-4ffe9a2a9aa9

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Input: mcs-touchkey - Fix uninitialized use of error in mcs_touchkey_probe()
  2023-07-25 15:37 [PATCH] Input: mcs-touchkey - Fix uninitialized use of error in mcs_touchkey_probe() Nathan Chancellor
@ 2023-07-25 16:54 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2023-07-25 16:54 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: ndesaulniers, trix, frank.li, linux-input, llvm, patches

On Tue, Jul 25, 2023 at 08:37:56AM -0700, Nathan Chancellor wrote:
> Clang warns (or errors with CONFIG_WERROR=y):
> 
>   drivers/input/keyboard/mcs_touchkey.c:149:49: error: variable 'error' is uninitialized when used here [-Werror,-Wuninitialized]
>     149 |                 dev_err(&client->dev, "i2c read error[%d]\n", error);
>         |                                                               ^~~~~
>   include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
>     144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
>         |                                                                        ^~~~~~~~~~~
>   include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
>     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
>         |                                     ^~~~~~~~~~~
>   drivers/input/keyboard/mcs_touchkey.c:110:11: note: initialize the variable 'error' to silence this warning
>     110 |         int error;
>         |                  ^
>         |                   = 0
>   1 error generated.
> 
> A refactoring updated the error handling in this block but did not
> update the dev_err() call to use fw_ver instead of error. Do so now to
> fix the warning and avoid printing uninitialized memory.
> 
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1893
> Fixes: e175eae16c1b ("Input: mcs-touchkey - convert to use devm_* api")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-25 16:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25 15:37 [PATCH] Input: mcs-touchkey - Fix uninitialized use of error in mcs_touchkey_probe() Nathan Chancellor
2023-07-25 16:54 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox