mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: "Dan Carpenter" <dan.carpenter@linaro.org>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] media: rcar-csi2: Use common error handling code in rcsi2_parse_dt()
Date: Sun, 3 Mar 2024 09:36:09 +0100	[thread overview]
Message-ID: <af4995cf-6ea5-4214-a133-af260e2c517f@web.de> (raw)
In-Reply-To: <260d82b6-e7fc-40c3-b414-50a883709fd7@moroto.mountain>

> Sakari Ailus pointed out in another thread that we could use __free() instead.

See also:
Contributions by Jonathan Cameron from 2024-02-17

* device property: Move fwnode_handle_put() into property.h
  https://lore.kernel.org/r/20240217164249.921878-2-jic23@kernel.org

* device property: Add cleanup.h based fwnode_handle_put() scope based cleanup.
  https://lore.kernel.org/r/20240217164249.921878-3-jic23@kernel.org


> Something like this:
>
> diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c
> index 582d5e35db0e..c569df6057b7 100644
> --- a/drivers/media/platform/renesas/rcar-csi2.c
> +++ b/drivers/media/platform/renesas/rcar-csi2.c
> @@ -1372,8 +1372,8 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
>  static int rcsi2_parse_dt(struct rcar_csi2 *priv)
>  {
>  	struct v4l2_async_connection *asc;
> -	struct fwnode_handle *fwnode;
> -	struct fwnode_handle *ep;
> +	struct fwnode_handle *fwnode __free(fwnode_handle) = NULL;
> +	struct fwnode_handle *ep __free(fwnode_handle);
>  	struct v4l2_fwnode_endpoint v4l2_ep = {
>  		.bus_type = V4L2_MBUS_UNKNOWN,
>  	};

I suggest to reconsider the position for the adjusted variable declarations
a bit more.


> @@ -1388,18 +1388,14 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv)
>  	ret = v4l2_fwnode_endpoint_parse(ep, &v4l2_ep);
>  	if (ret) {
>  		dev_err(priv->dev, "Could not parse v4l2 endpoint\n");
> -		fwnode_handle_put(ep);
>  		return -EINVAL;
>  	}
>
>  	ret = rcsi2_parse_v4l2(priv, &v4l2_ep);
> -	if (ret) {
> -		fwnode_handle_put(ep);
> +	if (ret)
>  		return ret;
> -	}
>
>  	fwnode = fwnode_graph_get_remote_endpoint(ep);
> -	fwnode_handle_put(ep);
>
>  	dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(fwnode));
>
> @@ -1408,7 +1404,6 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv)
>
>  	asc = v4l2_async_nf_add_fwnode(&priv->notifier, fwnode,
>  				       struct v4l2_async_connection);
> -	fwnode_handle_put(fwnode);
>  	if (IS_ERR(asc))
>  		return PTR_ERR(asc);
>

I find that two function calls marked the end of scopes here
which obviously are not at the end of the discussed function implementation.
Thus I imagine that the known source code transformation “Reduce scope for variables”
will become relevant.
https://refactoring.com/catalog/reduceScopeOfVariable.html

Regards,
Markus

  reply	other threads:[~2024-03-03  8:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 12:10 Markus Elfring
2024-03-01 13:05 ` Geert Uytterhoeven
2024-03-01 13:42   ` Dan Carpenter
2024-03-03  8:36     ` Markus Elfring [this message]
2024-03-04 10:48     ` Sakari Ailus
2024-03-04 11:16       ` Dan Carpenter
2024-03-16  9:46         ` Niklas Söderlund
2024-03-16  9:54           ` Dan Carpenter
2024-03-16 10:18             ` Niklas Söderlund
2024-03-16 12:21             ` Markus Elfring
2024-03-01 13:15 ` [PATCH] " Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af4995cf-6ea5-4214-a133-af260e2c517f@web.de \
    --to=markus.elfring@web.de \
    --cc=dan.carpenter@linaro.org \
    --cc=geert@linux-m68k.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®