public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: trix@redhat.com
Cc: corbet@lwn.net, mchehab@kernel.org, natechancellor@gmail.com,
	ndesaulniers@google.com, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: ov7670: check status of ov7670_read
Date: Tue, 6 Oct 2020 15:41:48 +0300	[thread overview]
Message-ID: <20201006124148.GC5682@valkosipuli.retiisi.org.uk> (raw)
In-Reply-To: <20200828145518.26324-1-trix@redhat.com>

Hi Tom,

On Fri, Aug 28, 2020 at 07:55:18AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> clang static analysis flags this representative problem
> 
> drivers/media/i2c/ov7670.c:1463:9: warning: Assigned
>   value is garbage or undefined
>         *value = gain;
>                ^ ~~~~
> 
> gain is set by a successful call to ov7670_read()
> 
> So check that ov7670_read() is successful.
> 
> The remaining static analysis problems are false positives.
> There appears to be a limitation with checking the
> aggregated returns.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/media/i2c/ov7670.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
> index b42b289faaef..001d4b09db72 100644
> --- a/drivers/media/i2c/ov7670.c
> +++ b/drivers/media/i2c/ov7670.c
> @@ -929,6 +929,8 @@ static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop,
>  	ret =  ov7670_write(sd, REG_HSTART, (hstart >> 3) & 0xff);
>  	ret += ov7670_write(sd, REG_HSTOP, (hstop >> 3) & 0xff);
>  	ret += ov7670_read(sd, REG_HREF, &v);
> +	if (ret)
> +		return ret;

Thanks for the patch.

While the patch fixes a bug, could you also fix adding the return values?
These are valid error codes to begin with, but it makes no sense to add
them together.

>  	v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7);
>  	msleep(10);
>  	ret += ov7670_write(sd, REG_HREF, v);
> @@ -938,6 +940,8 @@ static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop,
>  	ret += ov7670_write(sd, REG_VSTART, (vstart >> 2) & 0xff);
>  	ret += ov7670_write(sd, REG_VSTOP, (vstop >> 2) & 0xff);
>  	ret += ov7670_read(sd, REG_VREF, &v);
> +	if (ret)
> +		return ret;
>  	v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3);
>  	msleep(10);
>  	ret += ov7670_write(sd, REG_VREF, v);
> @@ -1460,6 +1464,8 @@ static int ov7670_g_gain(struct v4l2_subdev *sd, __s32 *value)
>  	unsigned char gain;
>  
>  	ret = ov7670_read(sd, REG_GAIN, &gain);
> +	if (ret)
> +		return ret;
>  	*value = gain;
>  	return ret;
>  }
> @@ -1470,11 +1476,14 @@ static int ov7670_s_gain(struct v4l2_subdev *sd, int value)
>  	unsigned char com8;
>  
>  	ret = ov7670_write(sd, REG_GAIN, value & 0xff);
> +	if (ret)
> +		return ret;
>  	/* Have to turn off AGC as well */
> -	if (ret == 0) {
> -		ret = ov7670_read(sd, REG_COM8, &com8);
> -		ret = ov7670_write(sd, REG_COM8, com8 & ~COM8_AGC);
> -	}
> +	ret = ov7670_read(sd, REG_COM8, &com8);
> +	if (ret)
> +		return ret;
> +	ret = ov7670_write(sd, REG_COM8, com8 & ~COM8_AGC);
> +
>  	return ret;
>  }
>  

-- 
Regards,

Sakari Ailus

  parent reply	other threads:[~2020-10-06 12:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-28 14:55 [PATCH] media: ov7670: check status of ov7670_read trix
2020-08-28 15:13 ` Nick Desaulniers
2020-08-28 15:36   ` Tom Rix
2020-10-06 12:41 ` Sakari Ailus [this message]
2020-10-06 14:17   ` Tom Rix

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=20201006124148.GC5682@valkosipuli.retiisi.org.uk \
    --to=sakari.ailus@iki.fi \
    --cc=corbet@lwn.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=ndesaulniers@google.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox