Ignore:
Timestamp:
Apr 14, 2017, 9:41:36 PM (3 months ago)
Author:
brainslayer
Message:

kernel update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/linux/universal/linux-4.9/drivers/char/ppdev.c

    r31574 r31859  
    8585        struct ieee1284_info saved_state;
    8686        long default_inactivity;
     87        int index;
    8788};
     89
     90/* should we use PARDEVICE_MAX here? */
     91static struct device *devices[PARPORT_MAX];
     92
     93static DEFINE_IDA(ida_index);
    8894
    8995/* pp_struct.flags bitfields */
     
    288294        char *name;
    289295        struct pardev_cb ppdev_cb;
     296        int index;
    290297
    291298        name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
     
    300307        }
    301308
     309        index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
    302310        memset(&ppdev_cb, 0, sizeof(ppdev_cb));
    303311        ppdev_cb.irq_func = pp_irq;
    304312        ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
    305313        ppdev_cb.private = pp;
    306         pdev = parport_register_dev_model(port, name, &ppdev_cb, minor);
     314        pdev = parport_register_dev_model(port, name, &ppdev_cb, index);
    307315        parport_put_port(port);
    308316
    309317        if (!pdev) {
    310318                printk(KERN_WARNING "%s: failed to register device!\n", name);
     319                ida_simple_remove(&ida_index, index);
    311320                kfree(name);
    312321                return -ENXIO;
     
    314323
    315324        pp->pdev = pdev;
     325        pp->index = index;
    316326        dev_dbg(&pdev->dev, "registered pardevice\n");
    317327        return 0;
     
    750760        if (pp->pdev) {
    751761                parport_unregister_device(pp->pdev);
     762                ida_simple_remove(&ida_index, pp->index);
    752763                pp->pdev = NULL;
    753764                pr_debug(CHRDEV "%x: unregistered pardevice\n", minor);
     
    790801static void pp_attach(struct parport *port)
    791802{
    792         device_create(ppdev_class, port->dev, MKDEV(PP_MAJOR, port->number),
    793                       NULL, "parport%d", port->number);
     803        struct device *ret;
     804
     805        if (devices[port->number])
     806                return;
     807
     808        ret = device_create(ppdev_class, port->dev,
     809                            MKDEV(PP_MAJOR, port->number), NULL,
     810                            "parport%d", port->number);
     811        if (IS_ERR(ret)) {
     812                pr_err("Failed to create device parport%d\n",
     813                       port->number);
     814                return;
     815        }
     816        devices[port->number] = ret;
    794817}
    795818
    796819static void pp_detach(struct parport *port)
    797820{
     821        if (!devices[port->number])
     822                return;
     823
    798824        device_destroy(ppdev_class, MKDEV(PP_MAJOR, port->number));
     825        devices[port->number] = NULL;
    799826}
    800827
Note: See TracChangeset for help on using the changeset viewer.