diff mbox

[1/2] media: ov5645: Fix write_reg return code

Message ID 1518082920-11309-1-git-send-email-todor.tomov@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Todor Tomov Feb. 8, 2018, 9:41 a.m. UTC
I2C transfer functions return number of successful operations (on success).

Do not return the received positive return code but instead return 0 on
success. The users of write_reg function already use this logic.

Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
---
 drivers/media/i2c/ov5645.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Mauro Carvalho Chehab March 6, 2018, 1:40 p.m. UTC | #1
Em Thu,  8 Feb 2018 11:41:59 +0200
Todor Tomov <todor.tomov@linaro.org> escreveu:

> I2C transfer functions return number of successful operations (on success).
> 
> Do not return the received positive return code but instead return 0 on
> success. The users of write_reg function already use this logic.
> 
> Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> ---
>  drivers/media/i2c/ov5645.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index d28845f..9755562 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -600,11 +600,13 @@ static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
>  	regbuf[2] = val;
>  
>  	ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
>  			__func__, ret, reg, val);
> +		return ret;
> +	}

Actually, if ret < 3, it should return an error too (like -EREMOTEIO 
or -EIO).

>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int ov5645_read_reg(struct ov5645 *ov5645, u16 reg, u8 *val)



Thanks,
Mauro
Sakari Ailus March 6, 2018, 1:56 p.m. UTC | #2
HI Mauro,

On Tue, Mar 06, 2018 at 10:40:10AM -0300, Mauro Carvalho Chehab wrote:
> Em Thu,  8 Feb 2018 11:41:59 +0200
> Todor Tomov <todor.tomov@linaro.org> escreveu:
> 
> > I2C transfer functions return number of successful operations (on success).
> > 
> > Do not return the received positive return code but instead return 0 on
> > success. The users of write_reg function already use this logic.
> > 
> > Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> > ---
> >  drivers/media/i2c/ov5645.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> > index d28845f..9755562 100644
> > --- a/drivers/media/i2c/ov5645.c
> > +++ b/drivers/media/i2c/ov5645.c
> > @@ -600,11 +600,13 @@ static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
> >  	regbuf[2] = val;
> >  
> >  	ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
> > -	if (ret < 0)
> > +	if (ret < 0) {
> >  		dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
> >  			__func__, ret, reg, val);
> > +		return ret;
> > +	}
> 
> Actually, if ret < 3, it should return an error too (like -EREMOTEIO 
> or -EIO).

i2c_master_send() always returns a negative error code or the number of
octets written.

But thank you for reminding me about the patch. :-)
diff mbox

Patch

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index d28845f..9755562 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -600,11 +600,13 @@  static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
 	regbuf[2] = val;
 
 	ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
 			__func__, ret, reg, val);
+		return ret;
+	}
 
-	return ret;
+	return 0;
 }
 
 static int ov5645_read_reg(struct ov5645 *ov5645, u16 reg, u8 *val)