aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_io.c
diff options
context:
space:
mode:
authorRichard Watts <rrw@kynesim.co.uk>2015-05-19 11:06:53 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-08-03 18:24:43 -0400
commita3a10ce3429e5dee623ad5c8407ea58e204fcb0a (patch)
treee1a986e9e5e4c1c313f658eb70e599256c6d20c6 /drivers/tty/tty_io.c
parent458e2c82c5fbfbc431598636c05bdb21feb7056f (diff)
Avoid usb reset crashes by making tty_io cdevs truly dynamic
Avoid usb reset crashes by making tty_io cdevs truly dynamic Signed-off-by: Richard Watts <rrw@kynesim.co.uk> Reported-by: Duncan Mackintosh <DMackintosh@cbnl.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/tty_io.c')
-rw-r--r--drivers/tty/tty_io.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index c37a215177c0..02785d844354 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3152,9 +3152,12 @@ static int tty_cdev_add(struct tty_driver *driver, dev_t dev,
3152 unsigned int index, unsigned int count) 3152 unsigned int index, unsigned int count)
3153{ 3153{
3154 /* init here, since reused cdevs cause crashes */ 3154 /* init here, since reused cdevs cause crashes */
3155 cdev_init(&driver->cdevs[index], &tty_fops); 3155 driver->cdevs[index] = cdev_alloc();
3156 driver->cdevs[index].owner = driver->owner; 3156 if (!driver->cdevs[index])
3157 return cdev_add(&driver->cdevs[index], dev, count); 3157 return -ENOMEM;
3158 cdev_init(driver->cdevs[index], &tty_fops);
3159 driver->cdevs[index]->owner = driver->owner;
3160 return cdev_add(driver->cdevs[index], dev, count);
3158} 3161}
3159 3162
3160/** 3163/**
@@ -3260,8 +3263,10 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
3260 3263
3261error: 3264error:
3262 put_device(dev); 3265 put_device(dev);
3263 if (cdev) 3266 if (cdev) {
3264 cdev_del(&driver->cdevs[index]); 3267 cdev_del(driver->cdevs[index]);
3268 driver->cdevs[index] = NULL;
3269 }
3265 return ERR_PTR(retval); 3270 return ERR_PTR(retval);
3266} 3271}
3267EXPORT_SYMBOL_GPL(tty_register_device_attr); 3272EXPORT_SYMBOL_GPL(tty_register_device_attr);
@@ -3281,8 +3286,10 @@ void tty_unregister_device(struct tty_driver *driver, unsigned index)
3281{ 3286{
3282 device_destroy(tty_class, 3287 device_destroy(tty_class,
3283 MKDEV(driver->major, driver->minor_start) + index); 3288 MKDEV(driver->major, driver->minor_start) + index);
3284 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) 3289 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
3285 cdev_del(&driver->cdevs[index]); 3290 cdev_del(driver->cdevs[index]);
3291 driver->cdevs[index] = NULL;
3292 }
3286} 3293}
3287EXPORT_SYMBOL(tty_unregister_device); 3294EXPORT_SYMBOL(tty_unregister_device);
3288 3295
@@ -3347,6 +3354,7 @@ err_free_all:
3347 kfree(driver->ports); 3354 kfree(driver->ports);
3348 kfree(driver->ttys); 3355 kfree(driver->ttys);
3349 kfree(driver->termios); 3356 kfree(driver->termios);
3357 kfree(driver->cdevs);
3350 kfree(driver); 3358 kfree(driver);
3351 return ERR_PTR(err); 3359 return ERR_PTR(err);
3352} 3360}
@@ -3375,7 +3383,7 @@ static void destruct_tty_driver(struct kref *kref)
3375 } 3383 }
3376 proc_tty_unregister_driver(driver); 3384 proc_tty_unregister_driver(driver);
3377 if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC) 3385 if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)
3378 cdev_del(&driver->cdevs[0]); 3386 cdev_del(driver->cdevs[0]);
3379 } 3387 }
3380 kfree(driver->cdevs); 3388 kfree(driver->cdevs);
3381 kfree(driver->ports); 3389 kfree(driver->ports);