* [PATCH 2/5] char: lp: detach the device when parallel port is removed
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
2018-12-07 14:27 ` [PATCH 3/5] char: lp: use first unused lp number while registering Sudip Mukherjee
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2018-12-07 14:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arnd Bergmann; +Cc: linux-kernel, Sudip Mukherjee
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
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/5] char: lp: use first unused lp number while registering
2018-12-07 14:27 [PATCH 1/5] char: lp: introduce list to save port number Sudip Mukherjee
2018-12-07 14:27 ` [PATCH 2/5] char: lp: detach the device when parallel port is removed Sudip Mukherjee
@ 2018-12-07 14:27 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2018-12-07 14:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arnd Bergmann; +Cc: linux-kernel, Sudip Mukherjee
When the parallel port is usb based and the lp attaches to it based on
LP_PARPORT_AUTO, we do get /dev/lp0 and when we remove the usb device
/dev/lp0 is unregistered. But if we now reconnect the usb device we get
/dev/lp1, another disconnection and reconnection and we get /dev/lp2.
Use the port number array to find the first unused lp number and use
that to register the lp device with the parallel port.
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
drivers/char/lp.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index e21ed4007d0f..0e081f521f51 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -958,7 +958,11 @@ static void lp_attach(struct parport *port)
printk(KERN_INFO "lp: ignoring parallel port (max. %d)\n",LP_NO);
return;
}
- if (!lp_register(lp_count, port))
+ for (i = 0; i < LP_NO; i++)
+ if (port_num[i] == -1)
+ break;
+
+ if (!lp_register(i, port))
lp_count++;
break;
--
2.11.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/5] char: lp: properly count the lp devices
2018-12-07 14:27 [PATCH 1/5] char: lp: introduce list to save port number Sudip Mukherjee
2018-12-07 14:27 ` [PATCH 2/5] char: lp: detach the device when parallel port is removed Sudip Mukherjee
2018-12-07 14:27 ` [PATCH 3/5] char: lp: use first unused lp number while registering Sudip Mukherjee
@ 2018-12-07 14:27 ` Sudip Mukherjee
2018-12-07 14:27 ` [PATCH 5/5] char: lp: use new parport device model Sudip Mukherjee
3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2018-12-07 14:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arnd Bergmann; +Cc: linux-kernel, Sudip Mukherjee
When the parallel port is usb based and the lp attaches to it based on
LP_PARPORT_AUTO, we do get /dev/lp0 and when we remove the usb device
/dev/lp0 is unregistered. If we now reconnect the usb device we get
our /dev/lp0 back. But if we now disconnect and reconnect eight times
we donot get any lp device and dmesg shows:
lp: ignoring parallel port (max. 8)
Decrement the lp_count when the device detaches as this represents the
number of lp devices connected to the system.
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
drivers/char/lp.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 0e081f521f51..cef2ea386f5e 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -993,6 +993,7 @@ static void lp_detach(struct parport *port)
for (n = 0; n < LP_NO; n++) {
if (port_num[n] == port->number) {
port_num[n] = -1;
+ lp_count--;
device_destroy(lp_class, MKDEV(LP_MAJOR, n));
parport_unregister_device(lp_table[n].dev);
}
--
2.11.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 5/5] char: lp: use new parport device model
2018-12-07 14:27 [PATCH 1/5] char: lp: introduce list to save port number Sudip Mukherjee
` (2 preceding siblings ...)
2018-12-07 14:27 ` [PATCH 4/5] char: lp: properly count the lp devices Sudip Mukherjee
@ 2018-12-07 14:27 ` Sudip Mukherjee
3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2018-12-07 14:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arnd Bergmann; +Cc: linux-kernel, Sudip Mukherjee
Modify lp driver to use the new parallel port device model.
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
drivers/char/lp.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index cef2ea386f5e..5c8d780637bd 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -912,9 +912,13 @@ static int __init lp_setup(char *str)
static int lp_register(int nr, struct parport *port)
{
- lp_table[nr].dev = parport_register_device(port, "lp",
- lp_preempt, NULL, NULL, 0,
- (void *) &lp_table[nr]);
+ struct pardev_cb ppdev_cb;
+
+ memset(&ppdev_cb, 0, sizeof(ppdev_cb));
+ ppdev_cb.preempt = lp_preempt;
+ ppdev_cb.private = &lp_table[nr];
+ lp_table[nr].dev = parport_register_dev_model(port, "lp",
+ &ppdev_cb, nr);
if (lp_table[nr].dev == NULL)
return 1;
lp_table[nr].flags |= LP_EXIST;
@@ -1002,8 +1006,9 @@ static void lp_detach(struct parport *port)
static struct parport_driver lp_driver = {
.name = "lp",
- .attach = lp_attach,
+ .match_port = lp_attach,
.detach = lp_detach,
+ .devmodel = true,
};
static int __init lp_init(void)
--
2.11.0
^ permalink raw reply [flat|nested] 5+ messages in thread