From: trix@redhat.com
To: mchehab@kernel.org, sakari.ailus@linux.intel.com,
gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl,
drv@mailo.com, martinsdecarvalhobeatriz@gmail.com
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org, Tom Rix <trix@redhat.com>
Subject: [PATCH] media: staging: atomisp: improve error handling in gc2235_detect()
Date: Fri, 21 May 2021 12:48:05 -0700 [thread overview]
Message-ID: <20210521194805.2078135-1-trix@redhat.com> (raw)
From: Tom Rix <trix@redhat.com>
Static analysis reports this representative problem
atomisp-gc2235.c:867:20: warning: The right operand
of '|' is a garbage value
id = ((high << 8) | low);
^ ~~~
When gc2235_read_reg() fails, its return val is never written.
For gc2235_detect(), high and low are or-ed and compared
with GC2235_ID, 0x2235. Initialize both to 0 and skip
checking the read returns, it's errors are not passed up, only
-ENODEV is.
Signed-off-by: Tom Rix <trix@redhat.com>
---
drivers/staging/media/atomisp/i2c/atomisp-gc2235.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c b/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c
index 38defa0f81513..3b6e02b1f45d1 100644
--- a/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c
+++ b/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c
@@ -849,21 +849,14 @@ static int gc2235_get_fmt(struct v4l2_subdev *sd,
static int gc2235_detect(struct i2c_client *client)
{
struct i2c_adapter *adapter = client->adapter;
- u16 high, low;
- int ret;
+ u16 high = 0, low = 0;
u16 id;
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
return -ENODEV;
- ret = gc2235_read_reg(client, GC2235_8BIT,
- GC2235_SENSOR_ID_H, &high);
- if (ret) {
- dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
- return -ENODEV;
- }
- ret = gc2235_read_reg(client, GC2235_8BIT,
- GC2235_SENSOR_ID_L, &low);
+ gc2235_read_reg(client, GC2235_8BIT, GC2235_SENSOR_ID_H, &high);
+ gc2235_read_reg(client, GC2235_8BIT, GC2235_SENSOR_ID_L, &low);
id = ((high << 8) | low);
if (id != GC2235_ID) {
--
2.26.3
next reply other threads:[~2021-05-21 19:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-21 19:48 trix [this message]
2021-05-24 15:32 ` [PATCH] media: staging: atomisp: improve error handling in gc2235_detect() Sakari Ailus
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=20210521194805.2078135-1-trix@redhat.com \
--to=trix@redhat.com \
--cc=drv@mailo.com \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=martinsdecarvalhobeatriz@gmail.com \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.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 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).