lkml.org 
[lkml]   [2013]   [Jun]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] lp: implement proper detach function for parport_driver lp
Date
From: Hannes Weisbach <hannes_weisbach@gmx.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@gmx.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);


\
 
 \ /
  Last update: 2013-06-01 22:41    [W:0.065 / U:0.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site