* [PATCH] media: staging: atomisp: improve error handling in gc2235_detect()
@ 2021-05-21 19:48 trix
2021-05-24 15:32 ` Sakari Ailus
0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2021-05-21 19:48 UTC (permalink / raw)
To: mchehab, sakari.ailus, gregkh, hverkuil-cisco, drv,
martinsdecarvalhobeatriz
Cc: linux-media, linux-staging, linux-kernel, Tom Rix
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] media: staging: atomisp: improve error handling in gc2235_detect()
2021-05-21 19:48 [PATCH] media: staging: atomisp: improve error handling in gc2235_detect() trix
@ 2021-05-24 15:32 ` Sakari Ailus
0 siblings, 0 replies; 2+ messages in thread
From: Sakari Ailus @ 2021-05-24 15:32 UTC (permalink / raw)
To: trix
Cc: mchehab, gregkh, hverkuil-cisco, drv, martinsdecarvalhobeatriz,
linux-media, linux-staging, linux-kernel
Hi Tom,
On Fri, May 21, 2021 at 12:48:05PM -0700, trix@redhat.com wrote:
> 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;
It'd be nice if the function returned a different value for different
errors, such as there was an I/O error and that the ID was wrong.
> - }
> - 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) {
--
Sakari Ailus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-24 15:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 19:48 [PATCH] media: staging: atomisp: improve error handling in gc2235_detect() trix
2021-05-24 15:32 ` Sakari Ailus
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).