All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: dmitry.torokhov@gmail.com
Cc: ndesaulniers@google.com, trix@redhat.com, frank.li@vivo.com,
	 linux-input@vger.kernel.org, llvm@lists.linux.dev,
	patches@lists.linux.dev,  Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH] Input: mcs-touchkey - Fix uninitialized use of error in mcs_touchkey_probe()
Date: Tue, 25 Jul 2023 08:37:56 -0700	[thread overview]
Message-ID: <20230725-mcs_touchkey-fix-wuninitialized-v1-1-615db39af51c@kernel.org> (raw)

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>


             reply	other threads:[~2023-07-25 15:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 15:37 Nathan Chancellor [this message]
2023-07-25 16:54 ` [PATCH] Input: mcs-touchkey - Fix uninitialized use of error in mcs_touchkey_probe() Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230725-mcs_touchkey-fix-wuninitialized-v1-1-615db39af51c@kernel.org \
    --to=nathan@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=frank.li@vivo.com \
    --cc=linux-input@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=ndesaulniers@google.com \
    --cc=patches@lists.linux.dev \
    --cc=trix@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.