Input: i8042 add of_node_put()
diff mbox series

Message ID 20181121143513.22961-1-tiny.windzz@gmail.com
State Under Review
Headers show
Series
  • Input: i8042 add of_node_put()
Related show

Commit Message

Frank Lee Nov. 21, 2018, 2:35 p.m. UTC
use of_node_put() to release the refcount.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
 drivers/input/serio/i8042-sparcio.h | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

Dmitry Torokhov Nov. 29, 2018, 6:36 p.m. UTC | #1
Hi Yangtao,

On Wed, Nov 21, 2018 at 09:35:13AM -0500, Yangtao Li wrote:
> use of_node_put() to release the refcount.
> 
> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
> ---
>  drivers/input/serio/i8042-sparcio.h | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
> index 796289846204..5495bc035518 100644
> --- a/drivers/input/serio/i8042-sparcio.h
> +++ b/drivers/input/serio/i8042-sparcio.h
> @@ -108,18 +108,21 @@ static struct platform_driver sparc_i8042_driver = {
>  
>  static int __init i8042_platform_init(void)
>  {
> +	int rc;
>  	struct device_node *root = of_find_node_by_path("/");
>  
>  	if (!strcmp(root->name, "SUNW,JavaStation-1")) {
>  		/* Hardcoded values for MrCoffee.  */
>  		i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
>  		kbd_iobase = ioremap(0x71300060, 8);
> -		if (!kbd_iobase)
> -			return -ENODEV;
> +		if (!kbd_iobase){
> +			rc = -ENODEV;
> +			goto out;
> +		}
>  	} else {
> -		int err = platform_driver_register(&sparc_i8042_driver);
> -		if (err)
> -			return err;
> +		rc = platform_driver_register(&sparc_i8042_driver);
> +		if (rc)
> +			goto out;
>  
>  		if (i8042_kbd_irq == -1 ||
>  		    i8042_aux_irq == -1) {
> @@ -127,13 +130,18 @@ static int __init i8042_platform_init(void)
>  				of_iounmap(kbd_res, kbd_iobase, 8);
>  				kbd_iobase = (void __iomem *) NULL;
>  			}
> -			return -ENODEV;
> +			rc = -ENODEV;
> +			goto out;
>  		}
>  	}
>  
>  	i8042_reset = I8042_RESET_ALWAYS;
>  
> -	return 0;
> +	rc = 0;
> +out:
> +	of_node_put(root);
> +
> +	return rc;

Instead of rearranging code like this, can we instead have:

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;
}

?

Thanks.
Frank Lee Dec. 9, 2018, 5:22 a.m. UTC | #2
On Fri, Nov 30, 2018 at 2:37 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> Hi Yangtao,
>
> On Wed, Nov 21, 2018 at 09:35:13AM -0500, Yangtao Li wrote:
> > use of_node_put() to release the refcount.
> >
> > Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
> > ---
> >  drivers/input/serio/i8042-sparcio.h | 24 +++++++++++++++++-------
> >  1 file changed, 17 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
> > index 796289846204..5495bc035518 100644
> > --- a/drivers/input/serio/i8042-sparcio.h
> > +++ b/drivers/input/serio/i8042-sparcio.h
> > @@ -108,18 +108,21 @@ static struct platform_driver sparc_i8042_driver = {
> >
> >  static int __init i8042_platform_init(void)
> >  {
> > +     int rc;
> >       struct device_node *root = of_find_node_by_path("/");
> >
> >       if (!strcmp(root->name, "SUNW,JavaStation-1")) {
> >               /* Hardcoded values for MrCoffee.  */
> >               i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
> >               kbd_iobase = ioremap(0x71300060, 8);
> > -             if (!kbd_iobase)
> > -                     return -ENODEV;
> > +             if (!kbd_iobase){
> > +                     rc = -ENODEV;
> > +                     goto out;
> > +             }
> >       } else {
> > -             int err = platform_driver_register(&sparc_i8042_driver);
> > -             if (err)
> > -                     return err;
> > +             rc = platform_driver_register(&sparc_i8042_driver);
> > +             if (rc)
> > +                     goto out;
> >
> >               if (i8042_kbd_irq == -1 ||
> >                   i8042_aux_irq == -1) {
> > @@ -127,13 +130,18 @@ static int __init i8042_platform_init(void)
> >                               of_iounmap(kbd_res, kbd_iobase, 8);
> >                               kbd_iobase = (void __iomem *) NULL;
> >                       }
> > -                     return -ENODEV;
> > +                     rc = -ENODEV;
> > +                     goto out;
> >               }
> >       }
> >
> >       i8042_reset = I8042_RESET_ALWAYS;
> >
> > -     return 0;
> > +     rc = 0;
> > +out:
> > +     of_node_put(root);
> > +
> > +     return rc;
>
> Instead of rearranging code like this, can we instead have:
>
> 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;
> }
>
> ?
Yes, we should do this. The modified patch has been sent.
Also, I am very sorry to reply so late.

MBR,
Yangtao
>
> Thanks.
>
> --
> Dmitry

Patch
diff mbox series

diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 796289846204..5495bc035518 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -108,18 +108,21 @@  static struct platform_driver sparc_i8042_driver = {
 
 static int __init i8042_platform_init(void)
 {
+	int rc;
 	struct device_node *root = of_find_node_by_path("/");
 
 	if (!strcmp(root->name, "SUNW,JavaStation-1")) {
 		/* Hardcoded values for MrCoffee.  */
 		i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
 		kbd_iobase = ioremap(0x71300060, 8);
-		if (!kbd_iobase)
-			return -ENODEV;
+		if (!kbd_iobase){
+			rc = -ENODEV;
+			goto out;
+		}
 	} else {
-		int err = platform_driver_register(&sparc_i8042_driver);
-		if (err)
-			return err;
+		rc = platform_driver_register(&sparc_i8042_driver);
+		if (rc)
+			goto out;
 
 		if (i8042_kbd_irq == -1 ||
 		    i8042_aux_irq == -1) {
@@ -127,13 +130,18 @@  static int __init i8042_platform_init(void)
 				of_iounmap(kbd_res, kbd_iobase, 8);
 				kbd_iobase = (void __iomem *) NULL;
 			}
-			return -ENODEV;
+			rc = -ENODEV;
+			goto out;
 		}
 	}
 
 	i8042_reset = I8042_RESET_ALWAYS;
 
-	return 0;
+	rc = 0;
+out:
+	of_node_put(root);
+
+	return rc;
 }
 
 static inline void i8042_platform_exit(void)
@@ -142,6 +150,8 @@  static inline void i8042_platform_exit(void)
 
 	if (strcmp(root->name, "SUNW,JavaStation-1"))
 		platform_driver_unregister(&sparc_i8042_driver);
+
+	of_node_put(root);
 }
 
 #else /* !CONFIG_PCI */