From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>
Cc: linux-kernel@vger.kernel.org,
Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Subject: [PATCH 2/5] char: lp: detach the device when parallel port is removed
Date: Fri, 7 Dec 2018 14:27:31 +0000 [thread overview]
Message-ID: <20181207142734.27370-2-sudipm.mukherjee@gmail.com> (raw)
In-Reply-To: <20181207142734.27370-1-sudipm.mukherjee@gmail.com>
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>
---
drivers/char/lp.c | 19 ++++++++++---------
1 file 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);
}
--
2.11.0
next prev parent reply other threads:[~2018-12-07 14:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-07 14:27 [PATCH 1/5] char: lp: introduce list to save port number Sudip Mukherjee
2018-12-07 14:27 ` Sudip Mukherjee [this message]
2018-12-07 14:27 ` [PATCH 3/5] char: lp: use first unused lp number while registering Sudip Mukherjee
2018-12-07 14:27 ` [PATCH 4/5] char: lp: properly count the lp devices Sudip Mukherjee
2018-12-07 14:27 ` [PATCH 5/5] char: lp: use new parport device model Sudip Mukherjee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181207142734.27370-2-sudipm.mukherjee@gmail.com \
--to=sudipm.mukherjee@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®