public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] clocksource/drivers/timer-ti-dm: fix child node refcount handling
@ 2024-10-28 17:06 Javier Carrasco
  2024-10-28 17:06 ` [PATCH v2 1/2] " Javier Carrasco
  2024-10-28 17:06 ` [PATCH v2 2/2] clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init() Javier Carrasco
  0 siblings, 2 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-10-28 17:06 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Tony Lindgren
  Cc: linux-kernel, Javier Carrasco, stable

This series adds the missing calls to of_node_put(arm_timer) to release
the resource, and then switches to the more robust approach that makes
use of the automatic cleanup facility (not available for all stable
kernels).

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Changes in v2:
- Add second patch for automatic cleanup.
- Link to v1: https://lore.kernel.org/r/20241013-timer-ti-dm-systimer-of_node_put-v1-1-0cf0c9a37684@gmail.com

---
Javier Carrasco (2):
      clocksource/drivers/timer-ti-dm: fix child node refcount handling
      clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init()

 drivers/clocksource/timer-ti-dm-systimer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
base-commit: d61a00525464bfc5fe92c6ad713350988e492b88
change-id: 20241013-timer-ti-dm-systimer-of_node_put-d42735687698

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


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

* [PATCH v2 1/2] clocksource/drivers/timer-ti-dm: fix child node refcount handling
  2024-10-28 17:06 [PATCH v2 0/2] clocksource/drivers/timer-ti-dm: fix child node refcount handling Javier Carrasco
@ 2024-10-28 17:06 ` Javier Carrasco
  2024-10-28 17:06 ` [PATCH v2 2/2] clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init() Javier Carrasco
  1 sibling, 0 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-10-28 17:06 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Tony Lindgren
  Cc: linux-kernel, Javier Carrasco, stable

of_find_compatible_node() increments the node's refcount, and it must be
decremented again with a call to of_node_put() when the pointer is no
longer required to avoid leaking memory.

Add the missing calls to of_node_put() in dmtimer_percpu_quirck_init()
for the 'arm_timer' device node.

Cc: stable@vger.kernel.org
Fixes: 25de4ce5ed02 ("clocksource/drivers/timer-ti-dm: Handle dra7 timer wrap errata i940")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/clocksource/timer-ti-dm-systimer.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
index c2dcd8d68e45..23be1d21ce21 100644
--- a/drivers/clocksource/timer-ti-dm-systimer.c
+++ b/drivers/clocksource/timer-ti-dm-systimer.c
@@ -691,8 +691,10 @@ static int __init dmtimer_percpu_quirk_init(struct device_node *np, u32 pa)
 	arm_timer = of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
 	if (of_device_is_available(arm_timer)) {
 		pr_warn_once("ARM architected timer wrap issue i940 detected\n");
+		of_node_put(arm_timer);
 		return 0;
 	}
+	of_node_put(arm_timer);
 
 	if (pa == 0x4882c000)           /* dra7 dmtimer15 */
 		return dmtimer_percpu_timer_init(np, 0);

-- 
2.43.0


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

* [PATCH v2 2/2] clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init()
  2024-10-28 17:06 [PATCH v2 0/2] clocksource/drivers/timer-ti-dm: fix child node refcount handling Javier Carrasco
  2024-10-28 17:06 ` [PATCH v2 1/2] " Javier Carrasco
@ 2024-10-28 17:06 ` Javier Carrasco
  2024-10-31 11:09   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 4+ messages in thread
From: Javier Carrasco @ 2024-10-28 17:06 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Tony Lindgren
  Cc: linux-kernel, Javier Carrasco

Simplify the code and make it more robust by automating the node release
when it goes out of scope.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/clocksource/timer-ti-dm-systimer.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
index 23be1d21ce21..d1c144d6f328 100644
--- a/drivers/clocksource/timer-ti-dm-systimer.c
+++ b/drivers/clocksource/timer-ti-dm-systimer.c
@@ -686,15 +686,13 @@ subsys_initcall(dmtimer_percpu_timer_startup);
 
 static int __init dmtimer_percpu_quirk_init(struct device_node *np, u32 pa)
 {
-	struct device_node *arm_timer;
+	struct device_node *arm_timer __free(device_node) =
+		of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
 
-	arm_timer = of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
 	if (of_device_is_available(arm_timer)) {
 		pr_warn_once("ARM architected timer wrap issue i940 detected\n");
-		of_node_put(arm_timer);
 		return 0;
 	}
-	of_node_put(arm_timer);
 
 	if (pa == 0x4882c000)           /* dra7 dmtimer15 */
 		return dmtimer_percpu_timer_init(np, 0);

-- 
2.43.0


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

* Re: [PATCH v2 2/2] clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init()
  2024-10-28 17:06 ` [PATCH v2 2/2] clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init() Javier Carrasco
@ 2024-10-31 11:09   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-31 11:09 UTC (permalink / raw)
  To: Javier Carrasco, Daniel Lezcano, Thomas Gleixner, Tony Lindgren
  Cc: linux-kernel

On 28/10/2024 18:06, Javier Carrasco wrote:
> Simplify the code and make it more robust by automating the node release
> when it goes out of scope.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
>  drivers/clocksource/timer-ti-dm-systimer.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
> index 23be1d21ce21..d1c144d6f328 100644
> --- a/drivers/clocksource/timer-ti-dm-systimer.c
> +++ b/drivers/clocksource/timer-ti-dm-systimer.c
> @@ -686,15 +686,13 @@ subsys_initcall(dmtimer_percpu_timer_startup);
>  
>  static int __init dmtimer_percpu_quirk_init(struct device_node *np, u32 pa)
>  {
> -	struct device_node *arm_timer;
> +	struct device_node *arm_timer __free(device_node) =
> +		of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
>  
> -	arm_timer = of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
>  	if (of_device_is_available(arm_timer)) {
>  		pr_warn_once("ARM architected timer wrap issue i940 detected\n");
> -		of_node_put(arm_timer);


You just added this. Don't add code which is immediately removed. It's a
noop or wrong code.

Best regards,
Krzysztof


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

end of thread, other threads:[~2024-10-31 11:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28 17:06 [PATCH v2 0/2] clocksource/drivers/timer-ti-dm: fix child node refcount handling Javier Carrasco
2024-10-28 17:06 ` [PATCH v2 1/2] " Javier Carrasco
2024-10-28 17:06 ` [PATCH v2 2/2] clocksource/drivers/timer-ti-dm: automate device_node cleanup in dmtimer_percpu_quirk_init() Javier Carrasco
2024-10-31 11:09   ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox