virtio: console: fix race in port_fops_open() and port unplug
[pandora-kernel.git] / drivers / char / virtio_console.c
index 5746a36..6379ffa 100644 (file)
@@ -798,6 +798,10 @@ static int port_fops_open(struct inode *inode, struct file *filp)
 
        /* We get the port with a kref here */
        port = find_port_by_devt(cdev->dev);
+       if (!port) {
+               /* Port was unplugged before we could proceed */
+               return -ENXIO;
+       }
        filp->private_data = port;
 
        /*