virtio: console: Check if portdev is valid in send_control_msg()
authorAmit Shah <amit.shah@redhat.com>
Thu, 2 Sep 2010 12:41:42 +0000 (18:11 +0530)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 21 Oct 2010 07:14:00 +0000 (17:44 +1030)
A portdev may have been hot-unplugged while a port was open()ed.  Skip
sending control messages when the portdev isn't valid.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/char/virtio_console.c

index e15dbe7..e1d382b 100644 (file)
@@ -410,7 +410,10 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id,
 static ssize_t send_control_msg(struct port *port, unsigned int event,
                                unsigned int value)
 {
-       return __send_control_msg(port->portdev, port->id, event, value);
+       /* Did the port get unplugged before userspace closed it? */
+       if (port->portdev)
+               return __send_control_msg(port->portdev, port->id, event, value);
+       return 0;
 }
 
 /* Callers must take the port->outvq_lock */