diff mbox series

[v5,02/32] media: ov2680: Fix ov2680_bayer_order()

Message ID 20230803093348.15679-3-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show
Series media: ov2680: Bugfixes + ACPI + selection(crop-tgt) API support | expand

Commit Message

Hans de Goede Aug. 3, 2023, 9:33 a.m. UTC
The index into ov2680_hv_flip_bayer_order[] should be 0-3, but
ov2680_bayer_order() was using 0 + BIT(2) + (BIT(2) << 1) as
max index, while the intention was to use: 0 + 1 + 2 as max index.

Fix the index calculation in ov2680_bayer_order(), while at it
also just use the ctrl values rather then reading them back using
a slow i2c-read transaction.

This also allows making the function void, since there now are
no more i2c-reads to error check.

Note the check for the ctrls being NULL is there to allow
adding an ov2680_fill_format() helper later, which will call
ov2680_set_bayer_order() during probe() before the ctrls are created.

Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver")
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/i2c/ov2680.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Comments

Sakari Ailus Aug. 3, 2023, 12:48 p.m. UTC | #1
Hi Hans,

On Thu, Aug 03, 2023 at 11:33:17AM +0200, Hans de Goede wrote:
> The index into ov2680_hv_flip_bayer_order[] should be 0-3, but
> ov2680_bayer_order() was using 0 + BIT(2) + (BIT(2) << 1) as
> max index, while the intention was to use: 0 + 1 + 2 as max index.
> 
> Fix the index calculation in ov2680_bayer_order(), while at it
> also just use the ctrl values rather then reading them back using
> a slow i2c-read transaction.
> 
> This also allows making the function void, since there now are
> no more i2c-reads to error check.
> 
> Note the check for the ctrls being NULL is there to allow
> adding an ov2680_fill_format() helper later, which will call
> ov2680_set_bayer_order() during probe() before the ctrls are created.
> 
> Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver")
> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

This doesn't seem to compile:

> /home/jenkins/linux/drivers/media/i2c/ov2680.c: In function                   
'ov2680_vflip_disable':                                                         
> /home/jenkins/linux/drivers/media/i2c/ov2680.c:351:9: error: implicit         
declaration of function 'ov2680_bayer_order'; did you mean                      
'ov2680_set_bayer_order'? [-Werror=implicit-function-declaration]               
>   351 |  return ov2680_bayer_order(sensor);                                   
>       |         ^~~~~~~~~~~~~~~~~~                                            
>       |         ov2680_set_bayer_order                                        
> cc1: some warnings being treated as errors                                    

I guess you missed converting some calls?

> ---
>  drivers/media/i2c/ov2680.c | 27 ++++++++++-----------------
>  1 file changed, 10 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
> index 3a737a1607a4..621144f16fdc 100644
> --- a/drivers/media/i2c/ov2680.c
> +++ b/drivers/media/i2c/ov2680.c
> @@ -315,26 +315,17 @@ static void ov2680_power_down(struct ov2680_dev *sensor)
>  	usleep_range(5000, 10000);
>  }
>  
> -static int ov2680_bayer_order(struct ov2680_dev *sensor)
> +static void ov2680_set_bayer_order(struct ov2680_dev *sensor)
>  {
> -	u32 format1;
> -	u32 format2;
> -	u32 hv_flip;
> -	int ret;
> +	int hv_flip = 0;
>  
> -	ret = ov2680_read_reg(sensor, OV2680_REG_FORMAT1, &format1);
> -	if (ret < 0)
> -		return ret;
> +	if (sensor->ctrls.vflip && sensor->ctrls.vflip->val)
> +		hv_flip += 1;
>  
> -	ret = ov2680_read_reg(sensor, OV2680_REG_FORMAT2, &format2);
> -	if (ret < 0)
> -		return ret;
> -
> -	hv_flip = (format2 & BIT(2)  << 1) | (format1 & BIT(2));
> +	if (sensor->ctrls.hflip && sensor->ctrls.hflip->val)
> +		hv_flip += 2;
>  
>  	sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip];
> -
> -	return 0;
>  }
>  
>  static int ov2680_vflip_enable(struct ov2680_dev *sensor)
> @@ -345,7 +336,8 @@ static int ov2680_vflip_enable(struct ov2680_dev *sensor)
>  	if (ret < 0)
>  		return ret;
>  
> -	return ov2680_bayer_order(sensor);
> +	ov2680_set_bayer_order(sensor);
> +	return 0;
>  }
>  
>  static int ov2680_vflip_disable(struct ov2680_dev *sensor)
> @@ -378,7 +370,8 @@ static int ov2680_hflip_disable(struct ov2680_dev *sensor)
>  	if (ret < 0)
>  		return ret;
>  
> -	return ov2680_bayer_order(sensor);
> +	ov2680_set_bayer_order(sensor);
> +	return 0;
>  }
>  
>  static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value)
Sakari Ailus Aug. 3, 2023, 12:52 p.m. UTC | #2
On Thu, Aug 03, 2023 at 12:48:01PM +0000, Sakari Ailus wrote:
> Hi Hans,
> 
> On Thu, Aug 03, 2023 at 11:33:17AM +0200, Hans de Goede wrote:
> > The index into ov2680_hv_flip_bayer_order[] should be 0-3, but
> > ov2680_bayer_order() was using 0 + BIT(2) + (BIT(2) << 1) as
> > max index, while the intention was to use: 0 + 1 + 2 as max index.
> > 
> > Fix the index calculation in ov2680_bayer_order(), while at it
> > also just use the ctrl values rather then reading them back using
> > a slow i2c-read transaction.
> > 
> > This also allows making the function void, since there now are
> > no more i2c-reads to error check.
> > 
> > Note the check for the ctrls being NULL is there to allow
> > adding an ov2680_fill_format() helper later, which will call
> > ov2680_set_bayer_order() during probe() before the ctrls are created.
> > 
> > Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver")
> > Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
> > Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> 
> This doesn't seem to compile:
> 
> > /home/jenkins/linux/drivers/media/i2c/ov2680.c: In function                   
> 'ov2680_vflip_disable':                                                         
> > /home/jenkins/linux/drivers/media/i2c/ov2680.c:351:9: error: implicit         
> declaration of function 'ov2680_bayer_order'; did you mean                      
> 'ov2680_set_bayer_order'? [-Werror=implicit-function-declaration]               
> >   351 |  return ov2680_bayer_order(sensor);                                   
> >       |         ^~~~~~~~~~~~~~~~~~                                            
> >       |         ov2680_set_bayer_order                                        
> > cc1: some warnings being treated as errors                                    
> 
> I guess you missed converting some calls?

Actually the fix was trivial and the code is removed in the next patch
nonetheless. The change I made here was:

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 621144f16fdc..60c4e575aa86 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -348,7 +348,8 @@ static int ov2680_vflip_disable(struct ov2680_dev *sensor)
 	if (ret < 0)
 		return ret;
 
-	return ov2680_bayer_order(sensor);
+	ov2680_set_bayer_order(sensor);
+	return 0;
 }
 
 static int ov2680_hflip_enable(struct ov2680_dev *sensor)
@@ -359,7 +360,8 @@ static int ov2680_hflip_enable(struct ov2680_dev *sensor)
 	if (ret < 0)
 		return ret;
 
-	return ov2680_bayer_order(sensor);
+	ov2680_set_bayer_order(sensor);
+	return 0;
 }
 
 static int ov2680_hflip_disable(struct ov2680_dev *sensor)
Hans de Goede Aug. 3, 2023, 12:58 p.m. UTC | #3
Hi,

On 8/3/23 14:52, Sakari Ailus wrote:
> On Thu, Aug 03, 2023 at 12:48:01PM +0000, Sakari Ailus wrote:
>> Hi Hans,
>>
>> On Thu, Aug 03, 2023 at 11:33:17AM +0200, Hans de Goede wrote:
>>> The index into ov2680_hv_flip_bayer_order[] should be 0-3, but
>>> ov2680_bayer_order() was using 0 + BIT(2) + (BIT(2) << 1) as
>>> max index, while the intention was to use: 0 + 1 + 2 as max index.
>>>
>>> Fix the index calculation in ov2680_bayer_order(), while at it
>>> also just use the ctrl values rather then reading them back using
>>> a slow i2c-read transaction.
>>>
>>> This also allows making the function void, since there now are
>>> no more i2c-reads to error check.
>>>
>>> Note the check for the ctrls being NULL is there to allow
>>> adding an ov2680_fill_format() helper later, which will call
>>> ov2680_set_bayer_order() during probe() before the ctrls are created.
>>>
>>> Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver")
>>> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
>>> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>
>> This doesn't seem to compile:
>>
>>> /home/jenkins/linux/drivers/media/i2c/ov2680.c: In function                   
>> 'ov2680_vflip_disable':                                                         
>>> /home/jenkins/linux/drivers/media/i2c/ov2680.c:351:9: error: implicit         
>> declaration of function 'ov2680_bayer_order'; did you mean                      
>> 'ov2680_set_bayer_order'? [-Werror=implicit-function-declaration]               
>>>   351 |  return ov2680_bayer_order(sensor);                                   
>>>       |         ^~~~~~~~~~~~~~~~~~                                            
>>>       |         ov2680_set_bayer_order                                        
>>> cc1: some warnings being treated as errors                                    
>>
>> I guess you missed converting some calls?
> 
> Actually the fix was trivial and the code is removed in the next patch
> nonetheless. The change I made here was:

Yes the below changes are correct and I'm pretty sure I had that in there
at one point in time (I did compile test every patch for v2 or v3 IIRC).

I guess this somehow got messed up during a rebase, thank you for
fixing this.

Regards,

Hans




> 
> diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
> index 621144f16fdc..60c4e575aa86 100644
> --- a/drivers/media/i2c/ov2680.c
> +++ b/drivers/media/i2c/ov2680.c
> @@ -348,7 +348,8 @@ static int ov2680_vflip_disable(struct ov2680_dev *sensor)
>  	if (ret < 0)
>  		return ret;
>  
> -	return ov2680_bayer_order(sensor);
> +	ov2680_set_bayer_order(sensor);
> +	return 0;
>  }
>  
>  static int ov2680_hflip_enable(struct ov2680_dev *sensor)
> @@ -359,7 +360,8 @@ static int ov2680_hflip_enable(struct ov2680_dev *sensor)
>  	if (ret < 0)
>  		return ret;
>  
> -	return ov2680_bayer_order(sensor);
> +	ov2680_set_bayer_order(sensor);
> +	return 0;
>  }
>  
>  static int ov2680_hflip_disable(struct ov2680_dev *sensor)
>
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 3a737a1607a4..621144f16fdc 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -315,26 +315,17 @@  static void ov2680_power_down(struct ov2680_dev *sensor)
 	usleep_range(5000, 10000);
 }
 
-static int ov2680_bayer_order(struct ov2680_dev *sensor)
+static void ov2680_set_bayer_order(struct ov2680_dev *sensor)
 {
-	u32 format1;
-	u32 format2;
-	u32 hv_flip;
-	int ret;
+	int hv_flip = 0;
 
-	ret = ov2680_read_reg(sensor, OV2680_REG_FORMAT1, &format1);
-	if (ret < 0)
-		return ret;
+	if (sensor->ctrls.vflip && sensor->ctrls.vflip->val)
+		hv_flip += 1;
 
-	ret = ov2680_read_reg(sensor, OV2680_REG_FORMAT2, &format2);
-	if (ret < 0)
-		return ret;
-
-	hv_flip = (format2 & BIT(2)  << 1) | (format1 & BIT(2));
+	if (sensor->ctrls.hflip && sensor->ctrls.hflip->val)
+		hv_flip += 2;
 
 	sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip];
-
-	return 0;
 }
 
 static int ov2680_vflip_enable(struct ov2680_dev *sensor)
@@ -345,7 +336,8 @@  static int ov2680_vflip_enable(struct ov2680_dev *sensor)
 	if (ret < 0)
 		return ret;
 
-	return ov2680_bayer_order(sensor);
+	ov2680_set_bayer_order(sensor);
+	return 0;
 }
 
 static int ov2680_vflip_disable(struct ov2680_dev *sensor)
@@ -378,7 +370,8 @@  static int ov2680_hflip_disable(struct ov2680_dev *sensor)
 	if (ret < 0)
 		return ret;
 
-	return ov2680_bayer_order(sensor);
+	ov2680_set_bayer_order(sensor);
+	return 0;
 }
 
 static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value)