Skip to contentSkip to conversation

Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak

PATCH In review Yangtao Li 3 participants 4 messages Dec 15, 2018 – Dec 27, 2018

Subsystems (2)
lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH v5 1/1 Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. Add i8042_is_mr_coffee() helper to avoid refconut leak.

---
changes in v5:
-fix typo

changes in v4:
-fix typo

changes in v3:
-add i8042_is_mr_coffee

---
 drivers/input/serio/i8042-sparcio.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/input/serio/i8042-sparcio.h +16 -4
index 796289846204..9e9e512bc432 100644
@@ -106,11 +106,23 @@ static struct platform_driver sparc_i8042_driver = {
 	.remove		= sparc_i8042_remove,
 };
 
+static inline bool i8042_is_mr_coffee(void)
+{
+	struct device_node *root;
+	bool is_mr_coffee;
+
+	root = of_find_node_by_path("/");
+	is_mr_coffee = !strcmp(root->name, "SUNW,JavaStation-1");
+	of_node_put(root);
+
+	return is_mr_coffee;
+}
+
 static int __init i8042_platform_init(void)
 {
-	struct device_node *root = of_find_node_by_path("/");
+	bool match = i8042_is_mr_coffee();
 
-	if (!strcmp(root->name, "SUNW,JavaStation-1")) {
+	if (match) {
 		/* Hardcoded values for MrCoffee.  */
 		i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
 		kbd_iobase = ioremap(0x71300060, 8);
@@ -138,9 +150,9 @@ static int __init i8042_platform_init(void)
 
 static inline void i8042_platform_exit(void)
 {
-	struct device_node *root = of_find_node_by_path("/");
+	bool match = i8042_is_mr_coffee();
 
-	if (strcmp(root->name, "SUNW,JavaStation-1"))
+	if (!match)
 		platform_driver_unregister(&sparc_i8042_driver);
 }
 
Signature · 1 line
2.17.0
maintainer
#1 lore raw
Quoted 8 lines · Yangtao Li

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. Add i8042_is_mr_coffee() helper to avoid refconut leak.

---
changes in v5:
-fix typo

Has this at least been actually compiled by you?

Quoted 55 lines

changes in v4:
-fix typo

changes in v3:

(quoted diff) +0 -2
-add i8042_is_mr_coffee
---
 drivers/input/serio/i8042-sparcio.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/input/serio/i8042-sparcio.h +16 -4
index 796289846204..9e9e512bc432 100644
@@ -106,11 +106,23 @@ static struct platform_driver sparc_i8042_driver = {
 	.remove		= sparc_i8042_remove,
 };
 
+static inline bool i8042_is_mr_coffee(void)
+{
+	struct device_node *root;
+	bool is_mr_coffee;
+
+	root = of_find_node_by_path("/");
+	is_mr_coffee = !strcmp(root->name, "SUNW,JavaStation-1");
+	of_node_put(root);
+
+	return is_mr_coffee;
+}
+
 static int __init i8042_platform_init(void)
 {
-	struct device_node *root = of_find_node_by_path("/");
+	bool match = i8042_is_mr_coffee();
 
-	if (!strcmp(root->name, "SUNW,JavaStation-1")) {
+	if (match) {
 		/* Hardcoded values for MrCoffee.  */
 		i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
 		kbd_iobase = ioremap(0x71300060, 8);
@@ -138,9 +150,9 @@ static int __init i8042_platform_init(void)
 
 static inline void i8042_platform_exit(void)
 {
-	struct device_node *root = of_find_node_by_path("/");
+	bool match = i8042_is_mr_coffee();
 
-	if (strcmp(root->name, "SUNW,JavaStation-1"))
+	if (!match)
 		platform_driver_unregister(&sparc_i8042_driver);
 }
 
Signature · 1 line
2.17.0
Signature · 1 line
Dmitry
author
#2 lore raw
Quoted 6 lines · Dmitry Torokhov
Quoted 4 lines · Yangtao Li

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. Add i8042_is_mr_coffee() helper to avoid refconut leak.

Quoted 6 lines
Quoted 4 lines

---
changes in v5:
-fix typo

Has this at least been actually compiled by you?

Sure!!!
On ubuntu 18 machine.

MBR,
Yangtao

#3 lore raw
In reply to Yangtao Li
Quoted 3 lines · Yangtao Li

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. Add i8042_is_mr_coffee() helper to avoid refconut leak.

refconut->refcount, here and in subject.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html