diff mbox series

[v2,19/20] media: i2c: ov4689: Refactor ov4689_s_stream

Message ID 20231218174042.794012-20-mike.rudenko@gmail.com (mailing list archive)
State New
Headers show
Series Omnivision OV4689 refactoring and improvements | expand

Commit Message

Mikhail Rudenko Dec. 18, 2023, 5:40 p.m. UTC
Remove repetitive pm_runtime_put calls in ov4689_s_stream function,
and call pm_runtime_put once at the end of the "on" branch if any
error occurred.

Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
---
 drivers/media/i2c/ov4689.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

Comments

Laurent Pinchart Feb. 23, 2024, 11:48 a.m. UTC | #1
Hi Mikhail,

Thank you for the patch.

On Mon, Dec 18, 2023 at 08:40:40PM +0300, Mikhail Rudenko wrote:
> Remove repetitive pm_runtime_put calls in ov4689_s_stream function,
> and call pm_runtime_put once at the end of the "on" branch if any
> error occurred.
> 
> Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
> ---
>  drivers/media/i2c/ov4689.c | 29 ++++++++++-------------------
>  1 file changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c
> index e997c3231e85..884761d02119 100644
> --- a/drivers/media/i2c/ov4689.c
> +++ b/drivers/media/i2c/ov4689.c
> @@ -555,35 +555,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on)
>  					  ov4689_common_regs,
>  					  ARRAY_SIZE(ov4689_common_regs),
>  					  NULL);
> -		if (ret) {
> -			pm_runtime_put_sync(dev);
> -			goto unlock_and_return;
> -		}
> +		if (ret)
> +			goto cleanup_pm;
>  
>  		ret = ov4689_setup_timings(ov4689, sd_state);
> -		if (ret) {
> -			pm_runtime_put(dev);
> -			goto unlock_and_return;
> -		}
> +		if (ret)
> +			goto cleanup_pm;
>  
>  		ret = ov4689_setup_blc_anchors(ov4689, sd_state);
> -		if (ret) {
> -			pm_runtime_put(dev);
> -			goto unlock_and_return;
> -		}
> +		if (ret)
> +			goto cleanup_pm;
>  
>  		ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler);
> -		if (ret) {
> -			pm_runtime_put_sync(dev);
> -			goto unlock_and_return;
> -		}
> +		if (ret)
> +			goto cleanup_pm;
>  
>  		ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE,
>  				OV4689_MODE_STREAMING, NULL);
> -		if (ret) {
> +cleanup_pm:

A label within an if branch isn't great, readability-wise :-S Could we
maybe split the ov4687_s_stream() function in two (streamon and
streamoff, or similar names) ? You would then have a single
pm_runtime_put_sync() call in ov4689_s_stream(), in the error handling
path for the streamon function call.

> +		if (ret)
>  			pm_runtime_put_sync(dev);
> -			goto unlock_and_return;
> -		}
>  	} else {
>  		cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE,
>  			  OV4689_MODE_SW_STANDBY, NULL);
Mikhail Rudenko Feb. 23, 2024, 4:47 p.m. UTC | #2
Hi Laurent,

and thanks for the review!

On 2024-02-23 at 13:48 +02, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:

> Hi Mikhail,
>
> Thank you for the patch.
>
> On Mon, Dec 18, 2023 at 08:40:40PM +0300, Mikhail Rudenko wrote:
>> Remove repetitive pm_runtime_put calls in ov4689_s_stream function,
>> and call pm_runtime_put once at the end of the "on" branch if any
>> error occurred.
>>
>> Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
>> ---
>>  drivers/media/i2c/ov4689.c | 29 ++++++++++-------------------
>>  1 file changed, 10 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c
>> index e997c3231e85..884761d02119 100644
>> --- a/drivers/media/i2c/ov4689.c
>> +++ b/drivers/media/i2c/ov4689.c
>> @@ -555,35 +555,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on)
>>  					  ov4689_common_regs,
>>  					  ARRAY_SIZE(ov4689_common_regs),
>>  					  NULL);
>> -		if (ret) {
>> -			pm_runtime_put_sync(dev);
>> -			goto unlock_and_return;
>> -		}
>> +		if (ret)
>> +			goto cleanup_pm;
>>
>>  		ret = ov4689_setup_timings(ov4689, sd_state);
>> -		if (ret) {
>> -			pm_runtime_put(dev);
>> -			goto unlock_and_return;
>> -		}
>> +		if (ret)
>> +			goto cleanup_pm;
>>
>>  		ret = ov4689_setup_blc_anchors(ov4689, sd_state);
>> -		if (ret) {
>> -			pm_runtime_put(dev);
>> -			goto unlock_and_return;
>> -		}
>> +		if (ret)
>> +			goto cleanup_pm;
>>
>>  		ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler);
>> -		if (ret) {
>> -			pm_runtime_put_sync(dev);
>> -			goto unlock_and_return;
>> -		}
>> +		if (ret)
>> +			goto cleanup_pm;
>>
>>  		ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE,
>>  				OV4689_MODE_STREAMING, NULL);
>> -		if (ret) {
>> +cleanup_pm:
>
> A label within an if branch isn't great, readability-wise :-S Could we
> maybe split the ov4687_s_stream() function in two (streamon and
> streamoff, or similar names) ? You would then have a single
> pm_runtime_put_sync() call in ov4689_s_stream(), in the error handling
> path for the streamon function call.

Okay, will split it in v3.

>> +		if (ret)
>>  			pm_runtime_put_sync(dev);
>> -			goto unlock_and_return;
>> -		}
>>  	} else {
>>  		cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE,
>>  			  OV4689_MODE_SW_STANDBY, NULL);


--
Best regards,
Mikhail Rudenko
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c
index e997c3231e85..884761d02119 100644
--- a/drivers/media/i2c/ov4689.c
+++ b/drivers/media/i2c/ov4689.c
@@ -555,35 +555,26 @@  static int ov4689_s_stream(struct v4l2_subdev *sd, int on)
 					  ov4689_common_regs,
 					  ARRAY_SIZE(ov4689_common_regs),
 					  NULL);
-		if (ret) {
-			pm_runtime_put_sync(dev);
-			goto unlock_and_return;
-		}
+		if (ret)
+			goto cleanup_pm;
 
 		ret = ov4689_setup_timings(ov4689, sd_state);
-		if (ret) {
-			pm_runtime_put(dev);
-			goto unlock_and_return;
-		}
+		if (ret)
+			goto cleanup_pm;
 
 		ret = ov4689_setup_blc_anchors(ov4689, sd_state);
-		if (ret) {
-			pm_runtime_put(dev);
-			goto unlock_and_return;
-		}
+		if (ret)
+			goto cleanup_pm;
 
 		ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler);
-		if (ret) {
-			pm_runtime_put_sync(dev);
-			goto unlock_and_return;
-		}
+		if (ret)
+			goto cleanup_pm;
 
 		ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE,
 				OV4689_MODE_STREAMING, NULL);
-		if (ret) {
+cleanup_pm:
+		if (ret)
 			pm_runtime_put_sync(dev);
-			goto unlock_and_return;
-		}
 	} else {
 		cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE,
 			  OV4689_MODE_SW_STANDBY, NULL);