Skip to content

Commit fe5b6aa

Browse files
windhldtor
authored andcommitted
Input: i8042 - fix refount leak on sparc
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: f57caae ("[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>
1 parent fdd7c96 commit fe5b6aa

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

drivers/input/serio/i8042-sparcio.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _I8042_SPARCIO_H
44

55
#include <linux/of_device.h>
6+
#include <linux/types.h>
67

78
#include <asm/io.h>
89
#include <asm/oplib.h>
@@ -103,12 +104,25 @@ static struct platform_driver sparc_i8042_driver = {
103104
.remove = sparc_i8042_remove,
104105
};
105106

106-
static int __init i8042_platform_init(void)
107+
static bool i8042_is_mr_coffee(void)
107108
{
108-
struct device_node *root = of_find_node_by_path("/");
109-
const char *name = of_get_property(root, "name", NULL);
109+
struct device_node *root;
110+
const char *name;
111+
bool is_mr_coffee;
112+
113+
root = of_find_node_by_path("/");
114+
115+
name = of_get_property(root, "name", NULL);
116+
is_mr_coffee = name && !strcmp(name, "SUNW,JavaStation-1");
110117

111-
if (name && !strcmp(name, "SUNW,JavaStation-1")) {
118+
of_node_put(root);
119+
120+
return is_mr_coffee;
121+
}
122+
123+
static int __init i8042_platform_init(void)
124+
{
125+
if (i8042_is_mr_coffee()) {
112126
/* Hardcoded values for MrCoffee. */
113127
i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
114128
kbd_iobase = ioremap(0x71300060, 8);
@@ -136,10 +150,7 @@ static int __init i8042_platform_init(void)
136150

137151
static inline void i8042_platform_exit(void)
138152
{
139-
struct device_node *root = of_find_node_by_path("/");
140-
const char *name = of_get_property(root, "name", NULL);
141-
142-
if (!name || strcmp(name, "SUNW,JavaStation-1"))
153+
if (!i8042_is_mr_coffee())
143154
platform_driver_unregister(&sparc_i8042_driver);
144155
}
145156

0 commit comments

Comments
 (0)