[PATCH 3/5] media: i2c: imx214: Use __free(fwnode_handle)

André Apitzsch via B4 Relay posted 5 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH 3/5] media: i2c: imx214: Use __free(fwnode_handle)
Posted by André Apitzsch via B4 Relay 3 months, 1 week ago
From: André Apitzsch <git@apitzsch.eu>

Use the __free(fwnode_handle) hook to free the endpoint when the
function exits to simplify the error path.

While at it, simplify return if parsing endpoint node failed.

Signed-off-by: André Apitzsch <git@apitzsch.eu>
---
 drivers/media/i2c/imx214.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c
index d9193bafa3cbb8fec2679200c38d30077d1b11bd..b84197ee5177d609b1395e14e1404ffa5b9a6dbf 100644
--- a/drivers/media/i2c/imx214.c
+++ b/drivers/media/i2c/imx214.c
@@ -1326,8 +1326,8 @@ static int imx214_identify_module(struct imx214 *imx214)
 
 static int imx214_parse_fwnode(struct imx214 *imx214)
 {
+	struct fwnode_handle *endpoint __free(fwnode_handle) = NULL;
 	struct v4l2_fwnode_endpoint *bus_cfg = &imx214->bus_cfg;
-	struct fwnode_handle *endpoint;
 	struct device *dev = imx214->dev;
 	unsigned int i;
 	int ret;
@@ -1338,11 +1338,8 @@ static int imx214_parse_fwnode(struct imx214 *imx214)
 
 	bus_cfg->bus_type = V4L2_MBUS_CSI2_DPHY;
 	ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, bus_cfg);
-	fwnode_handle_put(endpoint);
-	if (ret) {
-		dev_err_probe(dev, ret, "parsing endpoint node failed\n");
-		goto error;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "parsing endpoint node failed\n");
 
 	/* Check the number of MIPI CSI2 data lanes */
 	if (bus_cfg->bus.mipi_csi2.num_data_lanes != 4) {

-- 
2.50.0


Re: [PATCH 3/5] media: i2c: imx214: Use __free(fwnode_handle)
Posted by Laurent Pinchart 3 months, 1 week ago
Hi André,

Thank you for the patch.

On Sun, Jun 29, 2025 at 04:49:22PM +0200, André Apitzsch via B4 Relay wrote:
> From: André Apitzsch <git@apitzsch.eu>
> 
> Use the __free(fwnode_handle) hook to free the endpoint when the
> function exits to simplify the error path.
> 
> While at it, simplify return if parsing endpoint node failed.

I think I'd drop this sentence, I don't see where the patch brings a
simplification beside the error path simplification mentioned in the
previous sentence.

> 
> Signed-off-by: André Apitzsch <git@apitzsch.eu>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/i2c/imx214.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c
> index d9193bafa3cbb8fec2679200c38d30077d1b11bd..b84197ee5177d609b1395e14e1404ffa5b9a6dbf 100644
> --- a/drivers/media/i2c/imx214.c
> +++ b/drivers/media/i2c/imx214.c
> @@ -1326,8 +1326,8 @@ static int imx214_identify_module(struct imx214 *imx214)
>  
>  static int imx214_parse_fwnode(struct imx214 *imx214)
>  {
> +	struct fwnode_handle *endpoint __free(fwnode_handle) = NULL;
>  	struct v4l2_fwnode_endpoint *bus_cfg = &imx214->bus_cfg;
> -	struct fwnode_handle *endpoint;
>  	struct device *dev = imx214->dev;
>  	unsigned int i;
>  	int ret;
> @@ -1338,11 +1338,8 @@ static int imx214_parse_fwnode(struct imx214 *imx214)
>  
>  	bus_cfg->bus_type = V4L2_MBUS_CSI2_DPHY;
>  	ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, bus_cfg);
> -	fwnode_handle_put(endpoint);
> -	if (ret) {
> -		dev_err_probe(dev, ret, "parsing endpoint node failed\n");
> -		goto error;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret, "parsing endpoint node failed\n");
>  
>  	/* Check the number of MIPI CSI2 data lanes */
>  	if (bus_cfg->bus.mipi_csi2.num_data_lanes != 4) {

-- 
Regards,

Laurent Pinchart