[PATCH] lp: implement proper detach function for parport_driver lp

From: Hannes Weisbach
Date: Sat Jun 01 2013 - 16:02:43 EST

From: Hannes Weisbach <hannes_weisbach@xxxxxxx>

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@xxxxxxx>
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);
+ }
+ }
if (console_registered == port) {

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/