lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 3 Mar 2024 09:36:09 +0100
From: Markus Elfring <Markus.Elfring@....de>
To: Dan Carpenter <dan.carpenter@...aro.org>,
 Geert Uytterhoeven <geert@...ux-m68k.org>,
 Sakari Ailus <sakari.ailus@...ux.intel.com>,
 linux-renesas-soc@...r.kernel.org, linux-media@...r.kernel.org,
 kernel-janitors@...r.kernel.org, Mauro Carvalho Chehab <mchehab@...nel.org>,
 Niklas Söderlund <niklas.soderlund@...natech.se>
Cc: LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] media: rcar-csi2: Use common error handling code in
 rcsi2_parse_dt()

> 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ