]> git.baikalelectronics.ru Git - kernel.git/commitdiff
misc: bcm-vk: fix tty registration race
authorJohan Hovold <johan@kernel.org>
Fri, 17 Sep 2021 11:57:36 +0000 (13:57 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 Sep 2021 14:17:15 +0000 (16:17 +0200)
Make sure to set the tty class-device driver data before registering the
tty to avoid having a racing open() dereference a NULL pointer.

Fixes: 11c370bc3b2f ("misc: bcm-vk: add ttyVK support")
Cc: stable@vger.kernel.org # 5.12
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210917115736.5816-1-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/bcm-vk/bcm_vk_tty.c

index 1b6076a89ca6ae4d0bc69bd5b51a7bf159c3f61a..6669625ba4c8d58eb8584559a495990aa695f93f 100644 (file)
@@ -267,13 +267,13 @@ int bcm_vk_tty_init(struct bcm_vk *vk, char *name)
                struct device *tty_dev;
 
                tty_port_init(&vk->tty[i].port);
-               tty_dev = tty_port_register_device(&vk->tty[i].port, tty_drv,
-                                                  i, dev);
+               tty_dev = tty_port_register_device_attr(&vk->tty[i].port,
+                                                       tty_drv, i, dev, vk,
+                                                       NULL);
                if (IS_ERR(tty_dev)) {
                        err = PTR_ERR(tty_dev);
                        goto unwind;
                }
-               dev_set_drvdata(tty_dev, vk);
                vk->tty[i].is_opened = false;
        }