summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>2018-12-07 14:27:31 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-12-19 10:40:17 +0100
commitd6318c0e8318c200aa95b50769d3635907381c08 (patch)
tree0be847f7b75c128ea4713fcd6aa33e8c3f851561 /drivers
parent0edf39d2c7dbb4947358dd102b6ff35eaaa92d68 (diff)
char: lp: detach the device when parallel port is removed
When the parallel port is usb based and the lp attaches to it, we do get /dev/lp0, but when we remove the usb device and the parallel port is gone, we are still left with /dev/lp0. Unregister the device properly in the detach routine based on the port number it has connected to. Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/lp.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 7e207ff0f2fe..e21ed4007d0f 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -976,6 +976,8 @@ static void lp_attach(struct parport *port)
static void lp_detach(struct parport *port)
{
+ int n;
+
/* Write this some day. */
#ifdef CONFIG_LP_CONSOLE
if (console_registered == port) {
@@ -983,6 +985,14 @@ static void lp_detach(struct parport *port)
console_registered = NULL;
}
#endif /* CONFIG_LP_CONSOLE */
+
+ for (n = 0; n < LP_NO; n++) {
+ if (port_num[n] == port->number) {
+ port_num[n] = -1;
+ device_destroy(lp_class, MKDEV(LP_MAJOR, n));
+ parport_unregister_device(lp_table[n].dev);
+ }
+ }
}
static struct parport_driver lp_driver = {
@@ -1082,8 +1092,6 @@ static int __init lp_init_module(void)
static void lp_cleanup_module(void)
{
- unsigned int offset;
-
parport_unregister_driver(&lp_driver);
#ifdef CONFIG_LP_CONSOLE
@@ -1091,13 +1099,6 @@ static void lp_cleanup_module(void)
#endif
unregister_chrdev(LP_MAJOR, "lp");
- for (offset = 0; offset < LP_NO; offset++) {
- if (lp_table[offset].dev == NULL)
- continue;
- port_num[offset] = -1;
- parport_unregister_device(lp_table[offset].dev);
- device_destroy(lp_class, MKDEV(LP_MAJOR, offset));
- }
class_destroy(lp_class);
}