aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tty_io.c
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2007-05-06 17:49:33 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-07 15:12:53 -0400
commit543691a6cd70b606dd9bed5e77b120c5d9c5c506 (patch)
tree91d1033d6699e28393c7a2cae63727ac22db92ac /drivers/char/tty_io.c
parentb5637e65ee2cecd344b1f8ff750013f697d3ae16 (diff)
tty_register_driver: only allocate tty instances when defined
If device->num is zero we attempt to kmalloc() zero bytes. When SLUB is enabled this returns a null pointer and take that as an allocation failure and fail the device register. Check for no devices and avoid the allocation. [akpm: opportunistic kzalloc() conversion] Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/tty_io.c')
-rw-r--r--drivers/char/tty_io.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 7a32df594907..389da364e6b6 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -3720,11 +3720,10 @@ int tty_register_driver(struct tty_driver *driver)
3720 if (driver->flags & TTY_DRIVER_INSTALLED) 3720 if (driver->flags & TTY_DRIVER_INSTALLED)
3721 return 0; 3721 return 0;
3722 3722
3723 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 3723 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) {
3724 p = kmalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL); 3724 p = kzalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
3725 if (!p) 3725 if (!p)
3726 return -ENOMEM; 3726 return -ENOMEM;
3727 memset(p, 0, driver->num * 3 * sizeof(void *));
3728 } 3727 }
3729 3728
3730 if (!driver->major) { 3729 if (!driver->major) {