struct class *tty_class;
+static int tty_cdev_add(struct tty_driver *driver, dev_t dev,
+ 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);
+}
+
/**
* tty_register_device - register a tty device
* @driver: the tty driver that describes the tty device
struct device *tty_register_device(struct tty_driver *driver, unsigned index,
struct device *device)
{
+ struct device *ret;
char name[64];
dev_t dev = MKDEV(driver->major, driver->minor_start) + index;
+ bool cdev = false;
if (index >= driver->num) {
printk(KERN_ERR "Attempt to register invalid tty line number "
else
tty_line_name(driver, index, name);
- return device_create(tty_class, device, dev, NULL, name);
+ if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
+ int error = tty_cdev_add(driver, dev, index, 1);
+ if (error)
+ return ERR_PTR(error);
+ cdev = true;
+ }
+
+ ret = device_create(tty_class, device, dev, NULL, name);
+ if (IS_ERR(ret) && cdev)
+ cdev_del(&driver->cdevs[index]);
+
+ return ret;
}
EXPORT_SYMBOL(tty_register_device);
{
device_destroy(tty_class,
MKDEV(driver->major, driver->minor_start) + index);
+ if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC))
+ cdev_del(&driver->cdevs[index]);
}
EXPORT_SYMBOL(tty_unregister_device);
unsigned long flags)
{
struct tty_driver *driver;
+ unsigned int cdevs = 1;
int err;
if (!lines || (flags & TTY_DRIVER_UNNUMBERED_NODE && lines > 1))
err = -ENOMEM;
goto err_free_all;
}
+ cdevs = lines;
+ }
+
+ driver->cdevs = kcalloc(cdevs, sizeof(*driver->cdevs), GFP_KERNEL);
+ if (!driver->cdevs) {
+ err = -ENOMEM;
+ goto err_free_all;
}
return driver;
tty_unregister_device(driver, i);
}
proc_tty_unregister_driver(driver);
- cdev_del(&driver->cdev);
+ if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)
+ cdev_del(&driver->cdevs[0]);
}
+ kfree(driver->cdevs);
kfree(driver->ports);
kfree(driver->termios);
kfree(driver->ttys);
if (error < 0)
goto err;
- cdev_init(&driver->cdev, &tty_fops);
- driver->cdev.owner = driver->owner;
- error = cdev_add(&driver->cdev, dev, driver->num);
- if (error)
- goto err_unreg_char;
+ if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC) {
+ error = tty_cdev_add(driver, dev, 0, driver->num);
+ if (error)
+ goto err_unreg_char;
+ }
mutex_lock(&tty_mutex);
list_add(&driver->tty_drivers, &tty_drivers);