]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ppdev: check before attaching port
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Sat, 12 Nov 2016 21:22:12 +0000 (21:22 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Nov 2016 19:25:34 +0000 (20:25 +0100)
After parport starts using the device model, all pardevice drivers
should decide in their match_port callback function if they want to
attach with that particulatr port. ppdev has been converted to use the
new parport device-model code but pp_attach() tried to attach with all
the ports.
Create a new array of pointer and use that to remember the ports we
have attached. And use that information to skip attaching ports which
we have already attached.

Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/ppdev.c

index 85c63e49df7ffeec905280ab009301490c92c749..02819e0703c8eef503baf8333c88f105a591444b 100644 (file)
@@ -86,6 +86,9 @@ struct pp_struct {
        long default_inactivity;
 };
 
+/* should we use PARDEVICE_MAX here? */
+static struct device *devices[PARPORT_MAX];
+
 /* pp_struct.flags bitfields */
 #define PP_CLAIMED    (1<<0)
 #define PP_EXCL       (1<<1)
@@ -789,13 +792,29 @@ static const struct file_operations pp_fops = {
 
 static void pp_attach(struct parport *port)
 {
-       device_create(ppdev_class, port->dev, MKDEV(PP_MAJOR, port->number),
-                     NULL, "parport%d", port->number);
+       struct device *ret;
+
+       if (devices[port->number])
+               return;
+
+       ret = device_create(ppdev_class, port->dev,
+                           MKDEV(PP_MAJOR, port->number), NULL,
+                           "parport%d", port->number);
+       if (IS_ERR(ret)) {
+               pr_err("Failed to create device parport%d\n",
+                      port->number);
+               return;
+       }
+       devices[port->number] = ret;
 }
 
 static void pp_detach(struct parport *port)
 {
+       if (!devices[port->number])
+               return;
+
        device_destroy(ppdev_class, MKDEV(PP_MAJOR, port->number));
+       devices[port->number] = NULL;
 }
 
 static int pp_probe(struct pardevice *par_dev)