public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sysrq: Auto release device node using __free attribute
@ 2024-04-11 18:02 Roman Storozhenko
  2024-04-11 18:10 ` Greg KH
  2024-04-11 18:11 ` Greg KH
  0 siblings, 2 replies; 11+ messages in thread
From: Roman Storozhenko @ 2024-04-11 18:02 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, Julia.Lawall, skhan, javier.carrasco.cruz,
	linux-kernel, linux-serial, Roman Storozhenko

Add a cleanup function attribute '__free(device_node)' to the device node
pointer initialization statement and remove the pairing cleanup function
call of 'of_node_put' at the end of the function.
The '_free()' attrubute is introduced by scope-based resource management
in-kernel framework implemented in 'cleanup.h'. A pointer marked with
'__free()' attribute makes a compiler insert a cleanup function call
to the places where the pointer goes out of the scope. This feature
allows to get rid of manual cleanup function calls.

Suggested-by: Julia.Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Roman Storozhenko <romeusmeister@gmail.com>
---
This patch targets the next tree:
tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
tag: next-20240411
---
 drivers/tty/sysrq.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 02217e3c916b..1d1261f618c0 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -758,11 +758,12 @@ static void sysrq_detect_reset_sequence(struct sysrq_state *state,
 static void sysrq_of_get_keyreset_config(void)
 {
 	u32 key;
-	struct device_node *np;
 	struct property *prop;
 	const __be32 *p;
 
-	np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq");
+	struct device_node *np __free(device_node) =
+		of_find_node_by_path("/chosen/linux,sysrq-reset-seq");
+
 	if (!np) {
 		pr_debug("No sysrq node found");
 		return;
@@ -781,8 +782,6 @@ static void sysrq_of_get_keyreset_config(void)
 
 	/* Get reset timeout if any. */
 	of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms);
-
-	of_node_put(np);
 }
 #else
 static void sysrq_of_get_keyreset_config(void)
-- 
2.34.1


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

end of thread, other threads:[~2024-04-13 19:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11 18:02 [PATCH] sysrq: Auto release device node using __free attribute Roman Storozhenko
2024-04-11 18:10 ` Greg KH
2024-04-11 18:25   ` Roman Storozhenko
2024-04-12  5:22     ` Greg KH
2024-04-11 18:11 ` Greg KH
2024-04-11 18:17   ` Julia Lawall
2024-04-12  5:22     ` Greg KH
2024-04-12  6:21       ` Julia Lawall
2024-04-13 19:15       ` Julia Lawall
2024-04-11 18:28   ` Roman Storozhenko
2024-04-12  5:20     ` Greg KH

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