* [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak
@ 2018-12-15 9:08 Yangtao Li
2018-12-21 8:42 ` Dmitry Torokhov
2018-12-27 22:43 ` Pavel Machek
0 siblings, 2 replies; 4+ messages in thread
From: Yangtao Li @ 2018-12-15 9:08 UTC (permalink / raw)
To: dmitry.torokhov; +Cc: tiny.windzz, linux-input, linux-kernel
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 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(-)
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 796289846204..9e9e512bc432 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_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);
}
--
2.17.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak
2018-12-15 9:08 [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak Yangtao Li
@ 2018-12-21 8:42 ` Dmitry Torokhov
2018-12-21 14:45 ` Frank Lee
2018-12-27 22:43 ` Pavel Machek
1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2018-12-21 8:42 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Sat, Dec 15, 2018 at 04:08:46AM -0500, Yangtao Li wrote:
> 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 v5:
> -fix typo
Has this at least been actually compiled by you?
>
> 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(-)
>
> diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
> index 796289846204..9e9e512bc432 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_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);
> }
>
> --
> 2.17.0
>
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak
2018-12-21 8:42 ` Dmitry Torokhov
@ 2018-12-21 14:45 ` Frank Lee
0 siblings, 0 replies; 4+ messages in thread
From: Frank Lee @ 2018-12-21 14:45 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, Linux Kernel Mailing List
On Fri, Dec 21, 2018 at 4:42 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> On Sat, Dec 15, 2018 at 04:08:46AM -0500, Yangtao Li wrote:
> > 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 v5:
> > -fix typo
>
> Has this at least been actually compiled by you?
Sure!!!
On ubuntu 18 machine.
MBR,
Yangtao
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak
2018-12-15 9:08 [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak Yangtao Li
2018-12-21 8:42 ` Dmitry Torokhov
@ 2018-12-27 22:43 ` Pavel Machek
1 sibling, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2018-12-27 22:43 UTC (permalink / raw)
To: Yangtao Li; +Cc: dmitry.torokhov, linux-input, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 447 bytes --]
On Sat 2018-12-15 04:08:46, Yangtao Li wrote:
> 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
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-27 22:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-15 9:08 [PATCH v5] Input: i8042 add i8042_is_mr_coffee() helper to avoid refconut leak Yangtao Li
2018-12-21 8:42 ` Dmitry Torokhov
2018-12-21 14:45 ` Frank Lee
2018-12-27 22:43 ` Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).