tty: tty_io: fix driver refcount imbalance on error path
authorLin Yi <teroincn@163.com>
Fri, 10 May 2019 04:22:57 +0000 (12:22 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 24 May 2019 08:09:12 +0000 (10:09 +0200)
tty_lookup_driver take a reference to the struct tty_driver, but forget
to release it on the error path, lead to a memory leak.
add a tty_driver_kref_put before error return.

Signed-off-by: Lin Yi <teroincn@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_io.c

index 033ac7e6a70dbfe1fc28e71ab03cf17d43b45b88..566728fbaf3cd4717af9da3380c389592f67ab61 100644 (file)
@@ -1837,7 +1837,7 @@ static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
 static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
                int *index)
 {
-       struct tty_driver *driver;
+       struct tty_driver *driver = NULL;
 
        switch (device) {
 #ifdef CONFIG_VT
@@ -1858,6 +1858,8 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
                                break;
                        }
                }
+               if (driver)
+                       tty_driver_kref_put(driver);
                return ERR_PTR(-ENODEV);
        }
        default: