diff mbox series

[V2] tty: hvc: hvc_opal: eliminate uses of of_node_put()

Message ID 20240503135215.252635-1-dai.lu@exordes.com
State New
Headers show
Series [V2] tty: hvc: hvc_opal: eliminate uses of of_node_put() | expand

Commit Message

Lu Dai May 3, 2024, 1:52 p.m. UTC
Make use of the __free() cleanup handler to automatically free nodes
when they get out of scope.

Remove the need for a 'goto' as an effect.

Signed-off-by: Lu Dai <dai.lu@exordes.com>
---
Changes since v1:
Move the assignment of 'opal' to its declaration
Seperate the declaration of 'np'

 drivers/tty/hvc/hvc_opal.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Greg KH May 3, 2024, 1:58 p.m. UTC | #1
On Fri, May 03, 2024 at 04:52:15PM +0300, Lu Dai wrote:
> Make use of the __free() cleanup handler to automatically free nodes
> when they get out of scope.
> 
> Remove the need for a 'goto' as an effect.
> 
> Signed-off-by: Lu Dai <dai.lu@exordes.com>
> ---
> Changes since v1:
> Move the assignment of 'opal' to its declaration
> Seperate the declaration of 'np'
> 
>  drivers/tty/hvc/hvc_opal.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
> index 095c33ad10f8..c17e8343ea60 100644
> --- a/drivers/tty/hvc/hvc_opal.c
> +++ b/drivers/tty/hvc/hvc_opal.c
> @@ -327,19 +327,18 @@ static void udbg_init_opal_common(void)
>  
>  void __init hvc_opal_init_early(void)
>  {
> -	struct device_node *stdout_node = of_node_get(of_stdout);
> +	struct device_node *stdout_node __free(device_node) = of_node_get(of_stdout);
>  	const __be32 *termno;
>  	const struct hv_ops *ops;
>  	u32 index;
>  
>  	/* If the console wasn't in /chosen, try /ibm,opal */
>  	if (!stdout_node) {
> -		struct device_node *opal, *np;
> -
>  		/* Current OPAL takeover doesn't provide the stdout
>  		 * path, so we hard wire it
>  		 */
> -		opal = of_find_node_by_path("/ibm,opal/consoles");
> +		struct device_node *opal __free(device_node) =
> +			of_find_node_by_path("/ibm,opal/consoles");
>  		if (opal) {

No blank line?

>  			pr_devel("hvc_opal: Found consoles in new location\n");
>  		} else {
> @@ -350,13 +349,13 @@ void __init hvc_opal_init_early(void)
>  		}
>  		if (!opal)
>  			return;
> +		struct device_node *np;
>  		for_each_child_of_node(opal, np) {

Ick, no, don't do that please.  Take some time and become more familiar
with kernel coding style and issues, perhaps work in drivers/staging/
first, before attempting to do stuff like this that is not correct.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index 095c33ad10f8..c17e8343ea60 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -327,19 +327,18 @@  static void udbg_init_opal_common(void)
 
 void __init hvc_opal_init_early(void)
 {
-	struct device_node *stdout_node = of_node_get(of_stdout);
+	struct device_node *stdout_node __free(device_node) = of_node_get(of_stdout);
 	const __be32 *termno;
 	const struct hv_ops *ops;
 	u32 index;
 
 	/* If the console wasn't in /chosen, try /ibm,opal */
 	if (!stdout_node) {
-		struct device_node *opal, *np;
-
 		/* Current OPAL takeover doesn't provide the stdout
 		 * path, so we hard wire it
 		 */
-		opal = of_find_node_by_path("/ibm,opal/consoles");
+		struct device_node *opal __free(device_node) =
+			of_find_node_by_path("/ibm,opal/consoles");
 		if (opal) {
 			pr_devel("hvc_opal: Found consoles in new location\n");
 		} else {
@@ -350,13 +349,13 @@  void __init hvc_opal_init_early(void)
 		}
 		if (!opal)
 			return;
+		struct device_node *np;
 		for_each_child_of_node(opal, np) {
 			if (of_node_name_eq(np, "serial")) {
 				stdout_node = np;
 				break;
 			}
 		}
-		of_node_put(opal);
 	}
 	if (!stdout_node)
 		return;
@@ -382,13 +381,11 @@  void __init hvc_opal_init_early(void)
 		hvsilib_establish(&hvc_opal_boot_priv.hvsi);
 		pr_devel("hvc_opal: Found HVSI console\n");
 	} else
-		goto out;
+		return;
 	hvc_opal_boot_termno = index;
 	udbg_init_opal_common();
 	add_preferred_console("hvc", index, NULL);
 	hvc_instantiate(index, index, ops);
-out:
-	of_node_put(stdout_node);
 }
 
 #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_RAW