[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <2009349A-75FD-4D5F-8F25-F8FD78F1A5D8@gmx.net>
Date: Sat, 1 Jun 2013 22:02:21 +0200
From: Hannes Weisbach <hannes_weisbach@....net>
To: Arnd Bergmann <arnd@...db.de>, Greg Kroah-Hartman <greg@...ah.com>
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] lp: implement proper detach function for parport_driver lp
From: Hannes Weisbach <hannes_weisbach@....net>
The lp pardevice driver does not have a proper detach function. Consequently, parport_unregister_device() is not called when the underlying parport driver calls parport_remove_port(). As a result, the ref count of the parport driver's module does not go to zero and the driver module cannot be unloaded.
The attached patch unregisters all lp pardevices which are on the to-be-detached parport.
Signed-off-by: Hannes Weisbach <hannes_weisbach@....net>
---
Granted, for normal parport drivers this is usually not an issue, because the device does not go away. However, I am currently writing a Linux device driver for a USB to parallel port converter [0] and therefore need proper detaching. Additionally, the wrong ref count keeps me from simply rmmod my driver and insmod a new version while developing and testing.
drivers/char/lp.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 0913d79..57e6941 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -930,7 +930,17 @@ static void lp_attach (struct parport *port)
static void lp_detach (struct parport *port)
{
- /* Write this some day. */
+ int offset;
+
+ for (offset = 0; offset < LP_NO; offset++) {
+ if (lp_table[offset].dev == NULL)
+ continue;
+ if (lp_table[offset].dev->port == port) {
+ device_destroy(lp_class, MKDEV(LP_MAJOR, offset));
+ parport_unregister_device(lp_table[offset].dev);
+ }
+ }
+
#ifdef CONFIG_LP_CONSOLE
if (console_registered == port) {
unregister_console(&lpcons);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists