]> git.baikalelectronics.ru Git - kernel.git/commitdiff
Input: i8042 - fix refount leak on sparc
authorLiang He <windhl@126.com>
Sat, 1 Oct 2022 21:42:24 +0000 (14:42 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 10 Oct 2022 05:26:53 +0000 (22:26 -0700)
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: 5a2d7b904e01 ("[SERIO] i8042-sparcio.h: Convert to of_driver framework.")
Signed-off-by: Liang He <windhl@126.com>
Link: https://lore.kernel.org/r/20220711064300.358757-1-windhl@126.com
[dtor: rearranged i8042_is_mr_coffee() a bit]
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/serio/i8042-sparcio.h

index fce76812843bb47a0083fdd9a5c196c3b3bc32a1..c712c1fe060533045d5f10bf80f5f6bc00636632 100644 (file)
@@ -3,6 +3,7 @@
 #define _I8042_SPARCIO_H
 
 #include <linux/of_device.h>
+#include <linux/types.h>
 
 #include <asm/io.h>
 #include <asm/oplib.h>
@@ -103,12 +104,25 @@ static struct platform_driver sparc_i8042_driver = {
        .remove         = sparc_i8042_remove,
 };
 
-static int __init i8042_platform_init(void)
+static bool i8042_is_mr_coffee(void)
 {
-       struct device_node *root = of_find_node_by_path("/");
-       const char *name = of_get_property(root, "name", NULL);
+       struct device_node *root;
+       const char *name;
+       bool is_mr_coffee;
+
+       root = of_find_node_by_path("/");
+
+       name = of_get_property(root, "name", NULL);
+       is_mr_coffee = name && !strcmp(name, "SUNW,JavaStation-1");
 
-       if (name && !strcmp(name, "SUNW,JavaStation-1")) {
+       of_node_put(root);
+
+       return is_mr_coffee;
+}
+
+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 +150,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);
 }