Skip to content

Commit

Permalink
char: lp: detach the device when parallel port is removed
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
sudipm-mukherjee authored and gregkh committed Dec 19, 2018
1 parent 0edf39d commit d6318c0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions drivers/char/lp.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,13 +976,23 @@ 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) {
unregister_console(&lpcons);
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 = {
Expand Down Expand Up @@ -1082,22 +1092,13 @@ 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
unregister_console(&lpcons);
#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);
}

Expand Down

0 comments on commit d6318c0

Please sign in to comment.