unsigned int index, unsigned int count)
 {
        /* init here, since reused cdevs cause crashes */
-       cdev_init(&driver->cdevs[index], &tty_fops);
-       driver->cdevs[index].owner = driver->owner;
-       return cdev_add(&driver->cdevs[index], dev, count);
+       driver->cdevs[index] = cdev_alloc();
+       if (!driver->cdevs[index])
+               return -ENOMEM;
+       cdev_init(driver->cdevs[index], &tty_fops);
+       driver->cdevs[index]->owner = driver->owner;
+       return cdev_add(driver->cdevs[index], dev, count);
 }
 
 /**
 
 error:
        put_device(dev);
-       if (cdev)
-               cdev_del(&driver->cdevs[index]);
+       if (cdev) {
+               cdev_del(driver->cdevs[index]);
+               driver->cdevs[index] = NULL;
+       }
        return ERR_PTR(retval);
 }
 EXPORT_SYMBOL_GPL(tty_register_device_attr);
 {
        device_destroy(tty_class,
                MKDEV(driver->major, driver->minor_start) + index);
-       if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC))
-               cdev_del(&driver->cdevs[index]);
+       if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
+               cdev_del(driver->cdevs[index]);
+               driver->cdevs[index] = NULL;
+       }
 }
 EXPORT_SYMBOL(tty_unregister_device);
 
        kfree(driver->ports);
        kfree(driver->ttys);
        kfree(driver->termios);
+       kfree(driver->cdevs);
        kfree(driver);
        return ERR_PTR(err);
 }
                }
                proc_tty_unregister_driver(driver);
                if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)
-                       cdev_del(&driver->cdevs[0]);
+                       cdev_del(driver->cdevs[0]);
        }
        kfree(driver->cdevs);
        kfree(driver->ports);