[PATCH v2] input: serio: i8042-sparcio.h: Fix refcount leak bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 changelog:

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

 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@xxxxxxxxx/

 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




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux