public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Liang He <windhl@126•com>
To: mpe@ellerman•id.au, benh@kernel•crashing.org, paulus@samba•org,
	linuxppc-dev@lists•ozlabs.org, windhl@126•com
Subject: [PATCH v2] powerpc: kernel: legacy_serial: Fix missing of_node_put() in add_legacy_soc_port()
Date: Sat,  2 Jul 2022 09:37:14 +0800	[thread overview]
Message-ID: <20220702013714.263614-1-windhl@126.com> (raw)

We should call of_node_put() for the reference 'tsi' returned by
of_get_parent() which will increase the refcount.

Signed-off-by: Liang He <windhl@126•com>
---
 changelog:

 v2: use more conservative way to call of_node_put()
 v1: mov 'of_node_put()' into the 'if' condition

 v1 Link: https://lore.kernel.org/all/20220701130203.240023-1-windhl@126.com/

 arch/powerpc/kernel/legacy_serial.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index f048c424c525..cca72081b864 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -166,7 +166,7 @@ static int __init add_legacy_soc_port(struct device_node *np,
 {
 	u64 addr;
 	const __be32 *addrp;
-	struct device_node *tsi = of_get_parent(np);
+	struct device_node *tsi;
 
 	/* We only support ports that have a clock frequency properly
 	 * encoded in the device-tree.
@@ -194,12 +194,17 @@ static int __init add_legacy_soc_port(struct device_node *np,
 	/* Add port, irq will be dealt with later. We passed a translated
 	 * IO port value. It will be fixed up later along with the irq
 	 */
-	if (of_node_is_type(tsi, "tsi-bridge"))
+	tsi = of_get_parent(np);
+	if (of_node_is_type(tsi, "tsi-bridge")) {
+		of_node_put(tsi);
 		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
 				       0, legacy_port_flags, 0);
-	else
+	}
+	else {
+		of_node_put(tsi);
 		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
 				       0, legacy_port_flags, 0);
+	}
 }
 
 static int __init add_legacy_isa_port(struct device_node *np,
-- 
2.25.1


             reply	other threads:[~2022-07-02  1:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-02  1:37 Liang He [this message]
2022-09-05  3:25 ` [PATCH v2] powerpc: kernel: legacy_serial: Fix missing of_node_put() in add_legacy_soc_port() Michael Ellerman
2022-09-05  7:16   ` Liang He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220702013714.263614-1-windhl@126.com \
    --to=windhl@126$(echo .)com \
    --cc=benh@kernel$(echo .)crashing.org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=mpe@ellerman$(echo .)id.au \
    --cc=paulus@samba$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox