staging: media: tegra-video: Use common error handling code in tegra_vi_graph_parse_one()

Message ID dbebaea7-289c-47d9-ba06-cd58a10ea662@web.de
State New
Headers
Series staging: media: tegra-video: Use common error handling code in tegra_vi_graph_parse_one() |

Commit Message

Markus Elfring Feb. 29, 2024, 6:55 p.m. UTC
  From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 29 Feb 2024 19:44:36 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function implementation.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/staging/media/tegra-video/vi.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

--
2.44.0
  

Comments

Luca Ceresoli March 1, 2024, 5:39 p.m. UTC | #1
Hello Markus,

On Thu, 29 Feb 2024 19:55:46 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 29 Feb 2024 19:44:36 +0100
> 
> Add a jump target so that a bit of exception handling can be better reused
> at the end of this function implementation.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
  
Dan Carpenter March 2, 2024, 9:30 a.m. UTC | #2
On Fri, Mar 01, 2024 at 06:39:36PM +0100, Luca Ceresoli wrote:
> Hello Markus,
> 
> On Thu, 29 Feb 2024 19:55:46 +0100
> Markus Elfring <Markus.Elfring@web.de> wrote:
> 
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Thu, 29 Feb 2024 19:44:36 +0100
> > 
> > Add a jump target so that a bit of exception handling can be better reused
> > at the end of this function implementation.
> > 
> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> 
> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

These patches make the code worse.  If we're in the middle of a loop,
then we should clean up the partial loop before doing the goto.
Otherwise it creates a mess when we add a new allocation function after
the end of the loop.

Someone is going to add a _scoped() loop which uses cleanup.h magic to
call _put automatically.  This is a good option.

regards,
dan carpenter
  
Markus Elfring March 2, 2024, 10:40 a.m. UTC | #3
>>> Add a jump target so that a bit of exception handling can be better reused
>>> at the end of this function implementation.>> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
>
> These patches make the code worse.  If we're in the middle of a loop,
> then we should clean up the partial loop before doing the goto.
> Otherwise it creates a mess when we add a new allocation function after
> the end of the loop.

How does such a feedback fit to another known information source?

Section “7) Centralized exiting of functions”
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.8-rc6#n526


> Someone is going to add a _scoped() loop which uses cleanup.h magic to
> call _put automatically.  This is a good option.

I became also curious how scope-based resource management will influence
Linux coding styles further.
Will various collateral evolution become more interesting?

Regards,
Markus
  

Patch

diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index af6e3a0d8df4..5a08d9551f8b 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -1730,21 +1730,20 @@  static int tegra_vi_graph_parse_one(struct tegra_vi_channel *chan,
 			ret = PTR_ERR(tvge);
 			dev_err(vi->dev,
 				"failed to add subdev to notifier: %d\n", ret);
-			fwnode_handle_put(remote);
-			goto cleanup;
+			goto put_fwnode;
 		}

 		ret = tegra_vi_graph_parse_one(chan, remote);
-		if (ret < 0) {
-			fwnode_handle_put(remote);
-			goto cleanup;
-		}
+		if (ret < 0)
+			goto put_fwnode;

 		fwnode_handle_put(remote);
 	}

 	return 0;

+put_fwnode:
+	fwnode_handle_put(remote);
 cleanup:
 	dev_err(vi->dev, "failed parsing the graph: %d\n", ret);
 	v4l2_async_nf_cleanup(&chan->notifier);