diff mbox series

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

Message ID 20181209061428.19205-1-tiny.windzz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v3] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak | expand

Commit Message

Yangtao Li Dec. 9, 2018, 6:14 a.m. UTC
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.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
changes in v3:
-add i8042_is_mr_coffee
---
 drivers/input/serio/i8042-sparcio.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Comments

kernel test robot Dec. 10, 2018, 5:02 p.m. UTC | #1
Hi Yangtao,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on input/next]
[also build test ERROR on v4.20-rc6 next-20181207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Yangtao-Li/Input-i8042-add-i8042_is_mr_coffee-helper-to-avoid-refconut-leak/20181209-175146
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: sparc-defconfig (attached as .config)
compiler: sparc-linux-gcc (GCC) 8.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.1.0 make.cross ARCH=sparc 

All error/warnings (new ones prefixed by >>):

   In file included from drivers/input/serio/i8042.h:26,
                    from drivers/input/serio/i8042.c:132:
   drivers/input/serio/i8042-sparcio.h: In function 'i8042_is_mr_coffee':
>> drivers/input/serio/i8042-sparcio.h:118:9: error: 'is_mr_coffee' undeclared (first use in this function); did you mean 'is_mr_coffree'?
     return is_mr_coffee;
            ^~~~~~~~~~~~
            is_mr_coffree
   drivers/input/serio/i8042-sparcio.h:118:9: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/input/serio/i8042-sparcio.h:119:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^

vim +118 drivers/input/serio/i8042-sparcio.h

   108	
   109	static inline bool i8042_is_mr_coffee(void)
   110	{
   111		struct device_node *root;
   112		bool is_mr_coffree;
   113	
   114		root = of_find_node_by_path("/");
   115		is_mr_coffree = !strcmp(root->name, "SUNW,JavaStation-1");
   116		of_node_put(root);
   117	
 > 118		return is_mr_coffee;
 > 119	}
   120	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Yangtao Li Dec. 12, 2018, 4:37 p.m. UTC | #2
The newer has been sent.

Thanks,
Yangtao
diff mbox series

Patch

diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 796289846204..c8dc5b4b5e4f 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -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_coffree;
+
+	root = of_find_node_by_path("/");
+	is_mr_coffree = !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);
 }