2008-07-11 20:52:54

by Andres Salomon

[permalink] [raw]
Subject: [PATCH resend] ov7670: clean up ov7670_read semantics

[note: this should probably go in for 2.6.26, as it fixes a bug in
ov7670_s_fmt where we incorrectly think that we've failed because we
return !0]


Cortland Setlow pointed out a bug in ov7670.c where the result from
ov7670_read() was just being checked for !0, rather than <0. This
made me realize that ov7670_read's semantics were rather confusing;
it both fills in 'value' with the result, and returns it. This is
goes against general kernel convention; so rather than fixing callers,
let's fix the function.

This makes ov7670_read return <0 in the case of an error, and 0 upon
success. Thus, code like:

res = ov7670_read(...);
if (!res)
goto error;

..will work properly.

Signed-off-by: Cortland Setlow <[email protected]>
Signed-off-by: Andres Salomon <[email protected]>
Acked-by: Jonathan Corbet <[email protected]>
---
drivers/media/video/ov7670.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index 2bc6bdc..d7bfd30 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -406,8 +406,10 @@ static int ov7670_read(struct i2c_client *c,
unsigned char reg, int ret;

ret = i2c_smbus_read_byte_data(c, reg);
- if (ret >= 0)
+ if (ret >= 0) {
*value = (unsigned char) ret;
+ ret = 0;
+ }
return ret;
}

--
1.5.5.3


2008-07-11 22:20:29

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH resend] ov7670: clean up ov7670_read semantics

On Fri, 11 Jul 2008 16:52:16 -0400 Andres Salomon <[email protected]> wrote:

> [note: this should probably go in for 2.6.26, as it fixes a bug in
> ov7670_s_fmt where we incorrectly think that we've failed because we
> return !0]
>

In which case 2.6.25.x wants the fix as well?

>
> Cortland Setlow pointed out a bug in ov7670.c where the result from
> ov7670_read() was just being checked for !0, rather than <0. This
> made me realize that ov7670_read's semantics were rather confusing;
> it both fills in 'value' with the result, and returns it. This is
> goes against general kernel convention; so rather than fixing callers,
> let's fix the function.
>
> This makes ov7670_read return <0 in the case of an error, and 0 upon
> success. Thus, code like:
>
> res = ov7670_read(...);
> if (!res)
> goto error;
>
> ..will work properly.
>
> Signed-off-by: Cortland Setlow <[email protected]>
> Signed-off-by: Andres Salomon <[email protected]>
> Acked-by: Jonathan Corbet <[email protected]>
> ---
> drivers/media/video/ov7670.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
> index 2bc6bdc..d7bfd30 100644
> --- a/drivers/media/video/ov7670.c
> +++ b/drivers/media/video/ov7670.c
> @@ -406,8 +406,10 @@ static int ov7670_read(struct i2c_client *c,
> unsigned char reg, int ret;

You have some wordwrapping happening there.

> ret = i2c_smbus_read_byte_data(c, reg);
> - if (ret >= 0)
> + if (ret >= 0) {
> *value = (unsigned char) ret;
> + ret = 0;
> + }
> return ret;
> }
>
> --
> 1.5.5.3

2008-07-11 22:42:59

by Andres Salomon

[permalink] [raw]
Subject: Re: [PATCH resend] ov7670: clean up ov7670_read semantics

On Fri, 11 Jul 2008 15:19:19 -0700
Andrew Morton <[email protected]> wrote:

> On Fri, 11 Jul 2008 16:52:16 -0400 Andres Salomon
> <[email protected]> wrote:
>
> > [note: this should probably go in for 2.6.26, as it fixes a bug in
> > ov7670_s_fmt where we incorrectly think that we've failed because we
> > return !0]
> >
>
> In which case 2.6.25.x wants the fix as well?
>

Yep!

[...]
> > diff --git a/drivers/media/video/ov7670.c
> > b/drivers/media/video/ov7670.c index 2bc6bdc..d7bfd30 100644
> > --- a/drivers/media/video/ov7670.c
> > +++ b/drivers/media/video/ov7670.c
> > @@ -406,8 +406,10 @@ static int ov7670_read(struct i2c_client *c,
> > unsigned char reg, int ret;
>
> You have some wordwrapping happening there.
>

Eek, thanks. The original send wasn't line-wrapped, I'm not sure how
that happened.