浏览代码

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>
Andy Whitcroft 18 年之前
父节点
当前提交
543691a6cd
共有 1 个文件被更改,包括 2 次插入3 次删除
  1. 2 3
      drivers/char/tty_io.c

+ 2 - 3
drivers/char/tty_io.c

@@ -3720,11 +3720,10 @@ int tty_register_driver(struct tty_driver *driver)
 	if (driver->flags & TTY_DRIVER_INSTALLED)
 	if (driver->flags & TTY_DRIVER_INSTALLED)
 		return 0;
 		return 0;
 
 
-	if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
-		p = kmalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
+	if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) {
+		p = kzalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
 		if (!p)
 		if (!p)
 			return -ENOMEM;
 			return -ENOMEM;
-		memset(p, 0, driver->num * 3 * sizeof(void *));
 	}
 	}
 
 
 	if (!driver->major) {
 	if (!driver->major) {