All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] drivers: video: Simplify device_node cleanup using __free
@ 2024-04-18 19:43 Shresth Prasad
  2024-04-19 11:16 ` Daniel Thompson
  0 siblings, 1 reply; 5+ messages in thread
From: Shresth Prasad @ 2024-04-18 19:43 UTC (permalink / raw)
  To: lee, daniel.thompson, jingoohan1, deller
  Cc: dri-devel, linux-fbdev, linux-kernel, skhan,
	javier.carrasco.cruz, Shresth Prasad, Julia Lawall

Add `__free` function attribute to `np` device_node pointer
initialisation and remove of_node_put cleanup for this pointer.

The `__free` attribute is used for scope based cleanup instead of
manually freeing the resource using `of_node_put`, making cleanup
simpler and safer.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com>
---
 drivers/video/backlight/sky81452-backlight.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c
index eb18c6eb0ff0..3c5d8125080c 100644
--- a/drivers/video/backlight/sky81452-backlight.c
+++ b/drivers/video/backlight/sky81452-backlight.c
@@ -182,7 +182,7 @@ static const struct attribute_group sky81452_bl_attr_group = {
 static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 							struct device *dev)
 {
-	struct device_node *np = of_node_get(dev->of_node);
+	struct device_node *np __free(device_node) = of_node_get(dev->of_node);
 	struct sky81452_bl_platform_data *pdata;
 	int num_entry;
 	unsigned int sources[6];
@@ -194,10 +194,8 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	}
 
 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
-	if (!pdata) {
-		of_node_put(np);
+	if (!pdata)
 		return ERR_PTR(-ENOMEM);
-	}
 
 	of_property_read_string(np, "name", &pdata->name);
 	pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm");
@@ -217,7 +215,6 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 					num_entry);
 		if (ret < 0) {
 			dev_err(dev, "led-sources node is invalid.\n");
-			of_node_put(np);
 			return ERR_PTR(-EINVAL);
 		}
 
@@ -237,7 +234,6 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	if (ret < 0)
 		pdata->boost_current_limit = 2750;
 
-	of_node_put(np);
 	return pdata;
 }
 #else
-- 
2.44.0


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

* Re: [PATCH][next] drivers: video: Simplify device_node cleanup using __free
  2024-04-18 19:43 [PATCH][next] drivers: video: Simplify device_node cleanup using __free Shresth Prasad
@ 2024-04-19 11:16 ` Daniel Thompson
  2024-04-19 18:52   ` Shresth Prasad
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Thompson @ 2024-04-19 11:16 UTC (permalink / raw)
  To: Shresth Prasad
  Cc: lee, jingoohan1, deller, dri-devel, linux-fbdev, linux-kernel,
	skhan, javier.carrasco.cruz, Julia Lawall

^^^

Please fix the subject line to be "backlight: <driver>: ...". I came
very close to deleting this patch without reading it ;-) .


On Fri, Apr 19, 2024 at 01:13:02AM +0530, Shresth Prasad wrote:
> diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c
> index eb18c6eb0ff0..3c5d8125080c 100644
> --- a/drivers/video/backlight/sky81452-backlight.c
> +++ b/drivers/video/backlight/sky81452-backlight.c
> @@ -182,7 +182,7 @@ static const struct attribute_group sky81452_bl_attr_group = {
>  static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
>  							struct device *dev)
>  {
> -	struct device_node *np = of_node_get(dev->of_node);
> +	struct device_node *np __free(device_node) = of_node_get(dev->of_node);


Do we need to get dev->of_node at all? The device, which we are
borrowing, already owns a reference to the node so I don't see
any point in this function taking an extra one.

So why not simply make this:

	struct device_node *np = dev->of_node;


Daniel.

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

* Re: [PATCH][next] drivers: video: Simplify device_node cleanup using __free
  2024-04-19 11:16 ` Daniel Thompson
@ 2024-04-19 18:52   ` Shresth Prasad
  2024-04-19 19:43     ` Dmitry Baryshkov
  0 siblings, 1 reply; 5+ messages in thread
From: Shresth Prasad @ 2024-04-19 18:52 UTC (permalink / raw)
  To: daniel.thompson
  Cc: deller, dri-devel, javier.carrasco.cruz, jingoohan1,
	julia.lawall, lee, linux-fbdev, linux-kernel, shresthprasad7,
	skhan


> Please fix the subject line to be "backlight: <driver>: ...". I came
> very close to deleting this patch without reading it ;-) .

Really sorry about that, I'll fix it.

> Do we need to get dev->of_node at all? The device, which we are
> borrowing, already owns a reference to the node so I don't see
> any point in this function taking an extra one.
>
> So why not simply make this:
>
>     struct device_node *np = dev->of_node;

Looking at it again, I'm not sure why the call to `of_node_put` is there in the first place. I think removing it will be fine.

I'll fix both of these issues and send a patch v2.

Regards,
Shresth

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

* Re: [PATCH][next] drivers: video: Simplify device_node cleanup using __free
  2024-04-19 18:52   ` Shresth Prasad
@ 2024-04-19 19:43     ` Dmitry Baryshkov
  2024-04-20  7:11       ` Shresth Prasad
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Baryshkov @ 2024-04-19 19:43 UTC (permalink / raw)
  To: Shresth Prasad
  Cc: daniel.thompson, deller, dri-devel, javier.carrasco.cruz,
	jingoohan1, julia.lawall, lee, linux-fbdev, linux-kernel, skhan

On Sat, Apr 20, 2024 at 12:22:41AM +0530, Shresth Prasad wrote:
> 
> > Please fix the subject line to be "backlight: <driver>: ...". I came
> > very close to deleting this patch without reading it ;-) .
> 
> Really sorry about that, I'll fix it.
> 
> > Do we need to get dev->of_node at all? The device, which we are
> > borrowing, already owns a reference to the node so I don't see
> > any point in this function taking an extra one.
> >
> > So why not simply make this:
> >
> >     struct device_node *np = dev->of_node;
> 
> Looking at it again, I'm not sure why the call to `of_node_put` is there in the first place. I think removing it will be fine.
> 
> I'll fix both of these issues and send a patch v2.

Just a stupid quesiton: on which platform was this patch tested?

-- 
With best wishes
Dmitry

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

* Re: [PATCH][next] drivers: video: Simplify device_node cleanup using __free
  2024-04-19 19:43     ` Dmitry Baryshkov
@ 2024-04-20  7:11       ` Shresth Prasad
  0 siblings, 0 replies; 5+ messages in thread
From: Shresth Prasad @ 2024-04-20  7:11 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: daniel.thompson, deller, dri-devel, javier.carrasco.cruz,
	jingoohan1, julia.lawall, lee, linux-fbdev, linux-kernel, skhan

20 Apr 2024 1:13:42 am Dmitry Baryshkov <dmitry.baryshkov@linaro.org>:

> On Sat, Apr 20, 2024 at 12:22:41AM +0530, Shresth Prasad wrote:
>> 
>>> Please fix the subject line to be "backlight: <driver>: ...". I came
>>> very close to deleting this patch without reading it ;-) .
>> 
>> Really sorry about that, I'll fix it.
>> 
>>> Do we need to get dev->of_node at all? The device, which we are
>>> borrowing, already owns a reference to the node so I don't see
>>> any point in this function taking an extra one.
>>> 
>>> So why not simply make this:
>>> 
>>>     struct device_node *np = dev->of_node;
>> 
>> Looking at it again, I'm not sure why the call to `of_node_put` is there in the first place. I think removing it will be fine.
>> 
>> I'll fix both of these issues and send a patch v2.
> 
> Just a stupid quesiton: on which platform was this patch tested?
> 
> -- 
> With best wishes
> Dmitry
I tested the patch on a x86_64 qemu virtual machine

Regards,
Shresth

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

end of thread, other threads:[~2024-04-20  7:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-18 19:43 [PATCH][next] drivers: video: Simplify device_node cleanup using __free Shresth Prasad
2024-04-19 11:16 ` Daniel Thompson
2024-04-19 18:52   ` Shresth Prasad
2024-04-19 19:43     ` Dmitry Baryshkov
2024-04-20  7:11       ` Shresth Prasad

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.