linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] media: i2c: st-mipid02: replace of_node_put() with __free
@ 2024-04-27  9:56 R Sundar
  2024-04-29  8:52 ` Benjamin Mugnier
  0 siblings, 1 reply; 4+ messages in thread
From: R Sundar @ 2024-04-27  9:56 UTC (permalink / raw)
  To: benjamin.mugnier, sylvain.petinot, mchehab
  Cc: linux-media, linux-kernel, skhan, javier.carrasco.cruz, R Sundar,
	Julia Lawall

Use the new cleanup magic to replace of_node_put() with
__free(device_node) marking to auto release and to simplify the error
paths.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: R Sundar <prosunofficial@gmail.com>
---
 drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)

diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
index f250640729ca..d42a306530f3 100644
--- a/drivers/media/i2c/st-mipid02.c
+++ b/drivers/media/i2c/st-mipid02.c
@@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
 	struct i2c_client *client = bridge->i2c_client;
 	struct v4l2_async_connection *asd;
-	struct device_node *ep_node;
 	int ret;
 
 	/* parse rx (endpoint 0) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						0, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0);
 	if (!ep_node) {
 		dev_err(&client->dev, "unable to find port0 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
 	if (ret) {
 		dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n",
 			ret);
-		goto error_of_node_put;
+		return ret;
 	}
 
 	/* do some sanity checks */
 	if (ep.bus.mipi_csi2.num_data_lanes > 2) {
 		dev_err(&client->dev, "max supported data lanes is 2 / got %d",
 			ep.bus.mipi_csi2.num_data_lanes);
-		ret = -EINVAL;
-		goto error_of_node_put;
+		return -EINVAL;
 	}
 
 	/* register it for later use */
@@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 	asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
 					      of_fwnode_handle(ep_node),
 					      struct v4l2_async_connection);
-	of_node_put(ep_node);
 
 	if (IS_ERR(asd)) {
 		dev_err(&client->dev, "fail to register asd to notifier %ld",
@@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 		v4l2_async_nf_cleanup(&bridge->notifier);
 
 	return ret;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return ret;
 }
 
 static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
 {
 	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
 	struct i2c_client *client = bridge->i2c_client;
-	struct device_node *ep_node;
 	int ret;
 
 	/* parse tx (endpoint 2) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						2, 0);
+	struct device_node *ep_node =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0);
 	if (!ep_node) {
 		dev_err(&client->dev, "unable to find port1 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
 	if (ret) {
 		dev_err(&client->dev, "Could not parse v4l2 endpoint\n");
-		goto error_of_node_put;
+		return ret;
 	}
 
-	of_node_put(ep_node);
 	bridge->tx = ep;
 
 	return 0;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return -EINVAL;
 }
 
 static int mipid02_probe(struct i2c_client *client)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH linux-next] media: i2c: st-mipid02: replace of_node_put() with __free
  2024-04-27  9:56 [PATCH linux-next] media: i2c: st-mipid02: replace of_node_put() with __free R Sundar
@ 2024-04-29  8:52 ` Benjamin Mugnier
  2024-04-29  9:04   ` Sakari Ailus
  2024-04-29 16:02   ` R Sundar
  0 siblings, 2 replies; 4+ messages in thread
From: Benjamin Mugnier @ 2024-04-29  8:52 UTC (permalink / raw)
  To: R Sundar, sylvain.petinot, mchehab, Laurent Pinchart, Sakari Ailus
  Cc: linux-media, linux-kernel, skhan, javier.carrasco.cruz, Julia Lawall

Hi,

Thank you for your patch.

On 4/27/24 11:56, R Sundar wrote:
> Use the new cleanup magic to replace of_node_put() with
> __free(device_node) marking to auto release and to simplify the error
> paths.
> 
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: R Sundar <prosunofficial@gmail.com>

I was not aware of this kind of auto release mechanism. Thanks for
bringing that to my eyes.

Now I looked in /drivers/media and couldn't find such structure. All
drivers seem to follow the goto error_of_node_put style.
As I'm unsure if we want to introduce such magic, could either Laurent
or Sakari comment on this ?

> ---
>  drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------
>  1 file changed, 9 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index f250640729ca..d42a306530f3 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
>  	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
>  	struct i2c_client *client = bridge->i2c_client;
>  	struct v4l2_async_connection *asd;
> -	struct device_node *ep_node;
>  	int ret;
>  
>  	/* parse rx (endpoint 0) */
> -	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
> -						0, 0);
> +	struct device_node *ep_node __free(device_node) =
> +		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0);
>  	if (!ep_node) {
>  		dev_err(&client->dev, "unable to find port0 ep");
> -		ret = -EINVAL;
> -		goto error;
> +		return -EINVAL;
>  	}
>  
>  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
>  	if (ret) {
>  		dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n",
>  			ret);
> -		goto error_of_node_put;
> +		return ret;
>  	}
>  
>  	/* do some sanity checks */
>  	if (ep.bus.mipi_csi2.num_data_lanes > 2) {
>  		dev_err(&client->dev, "max supported data lanes is 2 / got %d",
>  			ep.bus.mipi_csi2.num_data_lanes);
> -		ret = -EINVAL;
> -		goto error_of_node_put;
> +		return -EINVAL;
>  	}
>  
>  	/* register it for later use */
> @@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
>  	asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
>  					      of_fwnode_handle(ep_node),
>  					      struct v4l2_async_connection);
> -	of_node_put(ep_node);
>  
>  	if (IS_ERR(asd)) {
>  		dev_err(&client->dev, "fail to register asd to notifier %ld",
> @@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
>  		v4l2_async_nf_cleanup(&bridge->notifier);
>  
>  	return ret;
> -
> -error_of_node_put:
> -	of_node_put(ep_node);
> -error:
> -
> -	return ret;
>  }
>  
>  static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
>  {
>  	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
>  	struct i2c_client *client = bridge->i2c_client;
> -	struct device_node *ep_node;
>  	int ret;
>  
>  	/* parse tx (endpoint 2) */
> -	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
> -						2, 0);
> +	struct device_node *ep_node =
> +		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0);

Shouldn't there be a '__free' here too ?

>  	if (!ep_node) {
>  		dev_err(&client->dev, "unable to find port1 ep");
> -		ret = -EINVAL;
> -		goto error;
> +		return -EINVAL;
>  	}
>  
>  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
>  	if (ret) {
>  		dev_err(&client->dev, "Could not parse v4l2 endpoint\n");
> -		goto error_of_node_put;
> +		return ret;
>  	}
>  
> -	of_node_put(ep_node);
>  	bridge->tx = ep;
>  
>  	return 0;
> -
> -error_of_node_put:
> -	of_node_put(ep_node);
> -error:
> -
> -	return -EINVAL;
>  }
>  
>  static int mipid02_probe(struct i2c_client *client)

-- 
Regards,

Benjamin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH linux-next] media: i2c: st-mipid02: replace of_node_put() with __free
  2024-04-29  8:52 ` Benjamin Mugnier
@ 2024-04-29  9:04   ` Sakari Ailus
  2024-04-29 16:02   ` R Sundar
  1 sibling, 0 replies; 4+ messages in thread
From: Sakari Ailus @ 2024-04-29  9:04 UTC (permalink / raw)
  To: Benjamin Mugnier
  Cc: R Sundar, sylvain.petinot, mchehab, Laurent Pinchart,
	linux-media, linux-kernel, skhan, javier.carrasco.cruz,
	Julia Lawall

Hi Benjamin,

On Mon, Apr 29, 2024 at 10:52:34AM +0200, Benjamin Mugnier wrote:
> Hi,
> 
> Thank you for your patch.
> 
> On 4/27/24 11:56, R Sundar wrote:
> > Use the new cleanup magic to replace of_node_put() with
> > __free(device_node) marking to auto release and to simplify the error
> > paths.
> > 
> > Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> > Signed-off-by: R Sundar <prosunofficial@gmail.com>
> 
> I was not aware of this kind of auto release mechanism. Thanks for
> bringing that to my eyes.
> 
> Now I looked in /drivers/media and couldn't find such structure. All
> drivers seem to follow the goto error_of_node_put style.
> As I'm unsure if we want to introduce such magic, could either Laurent
> or Sakari comment on this ?

It's new and little used so far. I don't have concerns using it, although
it's mostly useful in cases where all exit paths release the same resource.

-- 
Kind regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH linux-next] media: i2c: st-mipid02: replace of_node_put() with __free
  2024-04-29  8:52 ` Benjamin Mugnier
  2024-04-29  9:04   ` Sakari Ailus
@ 2024-04-29 16:02   ` R Sundar
  1 sibling, 0 replies; 4+ messages in thread
From: R Sundar @ 2024-04-29 16:02 UTC (permalink / raw)
  To: Benjamin Mugnier, sylvain.petinot, mchehab, Laurent Pinchart,
	Sakari Ailus
  Cc: linux-media, linux-kernel, skhan, javier.carrasco.cruz, Julia Lawall

On 29/04/24 14:22, Benjamin Mugnier wrote:
> Hi,
> 
> Thank you for your patch.
> 
> On 4/27/24 11:56, R Sundar wrote:
>> Use the new cleanup magic to replace of_node_put() with
>> __free(device_node) marking to auto release and to simplify the error
>> paths.
>>
>> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
>> Signed-off-by: R Sundar <prosunofficial@gmail.com>
> 
> I was not aware of this kind of auto release mechanism. Thanks for
> bringing that to my eyes.
> 
> Now I looked in /drivers/media and couldn't find such structure. All
> drivers seem to follow the goto error_of_node_put style.
> As I'm unsure if we want to introduce such magic, could either Laurent
> or Sakari comment on this ?
> 
>> ---
>>   drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------
>>   1 file changed, 9 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
>> index f250640729ca..d42a306530f3 100644
>> --- a/drivers/media/i2c/st-mipid02.c
>> +++ b/drivers/media/i2c/st-mipid02.c
>> @@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
>>   	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
>>   	struct i2c_client *client = bridge->i2c_client;
>>   	struct v4l2_async_connection *asd;
>> -	struct device_node *ep_node;
>>   	int ret;
>>   
>>   	/* parse rx (endpoint 0) */
>> -	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
>> -						0, 0);
>> +	struct device_node *ep_node __free(device_node) =
>> +		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0);
>>   	if (!ep_node) {
>>   		dev_err(&client->dev, "unable to find port0 ep");
>> -		ret = -EINVAL;
>> -		goto error;
>> +		return -EINVAL;
>>   	}
>>   
>>   	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
>>   	if (ret) {
>>   		dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n",
>>   			ret);
>> -		goto error_of_node_put;
>> +		return ret;
>>   	}
>>   
>>   	/* do some sanity checks */
>>   	if (ep.bus.mipi_csi2.num_data_lanes > 2) {
>>   		dev_err(&client->dev, "max supported data lanes is 2 / got %d",
>>   			ep.bus.mipi_csi2.num_data_lanes);
>> -		ret = -EINVAL;
>> -		goto error_of_node_put;
>> +		return -EINVAL;
>>   	}
>>   
>>   	/* register it for later use */
>> @@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
>>   	asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
>>   					      of_fwnode_handle(ep_node),
>>   					      struct v4l2_async_connection);
>> -	of_node_put(ep_node);
>>   
>>   	if (IS_ERR(asd)) {
>>   		dev_err(&client->dev, "fail to register asd to notifier %ld",
>> @@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
>>   		v4l2_async_nf_cleanup(&bridge->notifier);
>>   
>>   	return ret;
>> -
>> -error_of_node_put:
>> -	of_node_put(ep_node);
>> -error:
>> -
>> -	return ret;
>>   }
>>   
>>   static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
>>   {
>>   	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
>>   	struct i2c_client *client = bridge->i2c_client;
>> -	struct device_node *ep_node;
>>   	int ret;
>>   
>>   	/* parse tx (endpoint 2) */
>> -	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
>> -						2, 0);
>> +	struct device_node *ep_node =
>> +		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0);
> 
> Shouldn't there be a '__free' here too ?
> 

my Bad.
Yes, It should come here also. Thanks!!
Will update the patch.

Thanks,
Sundar



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-29 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-27  9:56 [PATCH linux-next] media: i2c: st-mipid02: replace of_node_put() with __free R Sundar
2024-04-29  8:52 ` Benjamin Mugnier
2024-04-29  9:04   ` Sakari Ailus
2024-04-29 16:02   ` R Sundar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).