All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liang He <windhl@126.com>
To: dmitry.torokhov@gmail.com, windhl@126.com, linux-input@vger.kernel.org
Subject: [PATCH v2] input: serio: i8042-sparcio.h: Fix refcount leak bug
Date: Mon, 11 Jul 2022 14:43:00 +0800	[thread overview]
Message-ID: <20220711064300.358757-1-windhl@126.com> (raw)

In i8042_platform_init() and i8042_platform_exit(), we should call
of_node_put() for the reference 'root' returned by
of_find_node_by_path() which has increased the refcount.

Fixes: f57caaefacc2 ("[SERIO] i8042-sparcio.h: Convert to of_driver framework.")
Signed-off-by: Liang He <windhl@126.com>
---
 changelog:

 v2: use a helper advised by Dmitry
 v1: directly add of_node_put() by:
 https://lore.kernel.org/all/20220619073036.4067872-1-windhl@126.com/

 Patched file has been compiled test with:
 *make CROSS_COMPILE=sparc64-linux-gnu- ARCH=sparc sparc32_defconfig*

 NOTE: this bug has been patched by Yangtao Li but might be with compiled error
 https://lore.kernel.org/all/20181215090846.28009-1-tiny.windzz@gmail.com/

 drivers/input/serio/i8042-sparcio.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index fce76812843b..c63186decab6 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -103,12 +103,23 @@ static struct platform_driver sparc_i8042_driver = {
 	.remove		= sparc_i8042_remove,
 };
 
-static int __init i8042_platform_init(void)
+static inline bool i8042_is_mr_coffee(void)
 {
 	struct device_node *root = of_find_node_by_path("/");
 	const char *name = of_get_property(root, "name", NULL);
+	bool ret = false;
+
+	if (name && !strcmp(name, "SUNW,JavaStation-1"))
+		ret = true;
+
+	of_node_put(root);
+
+	return ret;
+}
 
-	if (name && !strcmp(name, "SUNW,JavaStation-1")) {
+static int __init i8042_platform_init(void)
+{
+	if (i8042_is_mr_coffee()) {
 		/* Hardcoded values for MrCoffee.  */
 		i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
 		kbd_iobase = ioremap(0x71300060, 8);
@@ -136,10 +147,7 @@ static int __init i8042_platform_init(void)
 
 static inline void i8042_platform_exit(void)
 {
-	struct device_node *root = of_find_node_by_path("/");
-	const char *name = of_get_property(root, "name", NULL);
-
-	if (!name || strcmp(name, "SUNW,JavaStation-1"))
+	if (!i8042_is_mr_coffee())
 		platform_driver_unregister(&sparc_i8042_driver);
 }
 
-- 
2.25.1


                 reply	other threads:[~2022-07-11  6:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220711064300.358757-1-windhl@126.com \
    --to=windhl@126.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.