linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Linux Input <linux-input@vger.kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Grant Likely <grant.likely@secretlab.ca>
Subject: [PATCH] Input: i8042 - do not leak driver on error on Sparc
Date: Thu, 1 Dec 2011 00:40:40 -0800	[thread overview]
Message-ID: <20111201084040.GA31610@core.coreip.homeip.net> (raw)

If we did not find OF nodes describing AUX or KBD ports we'd bail
out but forget to unregister sparc_i8042_driver platform driver.

Switch over to platform_driver_probe() instead which automatically
unregisters driver if it does not bind to any device; it also has
a side effect of suppressing "bind" and "unbind" sysfs attributes
ensuring that we do not unmap IO registers while i8042 core is
running. This also allows us to switch annotations from
__devinit/__devexit to __init/__exit and maybe save some memory.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

1. This haven't even been compiled - I lost my sparc cross-compile
toolchain - but I hope I did not screw up.

2. I do not understand how it all even work - we register
sparc_i8042_driver which is a platform driver with 'i8042' name;
i8042 core also registers platform driver with exactly the same name.
Surely the core one will fail since it would be a duplicate...

Thanks.

 drivers/input/serio/i8042-sparcio.h |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)


diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 395a9af..be6512b 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -49,7 +49,7 @@ static inline void i8042_write_command(int val)
 #define OBP_PS2MS_NAME1		"kdmouse"
 #define OBP_PS2MS_NAME2		"mouse"
 
-static int __devinit sparc_i8042_probe(struct platform_device *op)
+static int __init sparc_i8042_probe(struct platform_device *op)
 {
 	struct device_node *dp = op->dev.of_node;
 
@@ -77,12 +77,23 @@ static int __devinit sparc_i8042_probe(struct platform_device *op)
 		dp = dp->sibling;
 	}
 
+	if (i8042_kbd_irq == -1 || i8042_aux_irq == -1) {
+		i8042_kbd_irq = i8042_aux_irq = -1;
+		if (kbd_iobase) {
+			of_iounmap(kbd_res, kbd_iobase, 8);
+			kbd_iobase = (void __iomem *) NULL;
+		}
+		return -ENODEV;
+	}
+
 	return 0;
 }
 
-static int __devexit sparc_i8042_remove(struct platform_device *op)
+static int __exit sparc_i8042_remove(struct platform_device *op)
 {
 	of_iounmap(kbd_res, kbd_iobase, 8);
+	kbd_iobase = (void __iomem *) NULL;
+	i8042_kbd_irq = i8042_aux_irq = -1;
 
 	return 0;
 }
@@ -101,8 +112,7 @@ static struct platform_driver sparc_i8042_driver = {
 		.owner = THIS_MODULE,
 		.of_match_table = sparc_i8042_match,
 	},
-	.probe		= sparc_i8042_probe,
-	.remove		= __devexit_p(sparc_i8042_remove),
+	.remove		= __exit_p(sparc_i8042_remove),
 };
 
 static int __init i8042_platform_init(void)
@@ -116,18 +126,10 @@ static int __init i8042_platform_init(void)
 		if (!kbd_iobase)
 			return -ENODEV;
 	} else {
-		int err = platform_driver_register(&sparc_i8042_driver);
+		int err = platform_driver_probe(&sparc_i8042_driver,
+						sparc_i8042_probe);
 		if (err)
 			return err;
-
-		if (i8042_kbd_irq == -1 ||
-		    i8042_aux_irq == -1) {
-			if (kbd_iobase) {
-				of_iounmap(kbd_res, kbd_iobase, 8);
-				kbd_iobase = (void __iomem *) NULL;
-			}
-			return -ENODEV;
-		}
 	}
 
 	i8042_reset = 1;
-- 
Dmitry

                 reply	other threads:[~2011-12-01  8:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111201084040.GA31610@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=davem@davemloft.net \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).