Skip to content

Commit da1ced7

Browse files
mstsirkinbwhacks
authored andcommitted
virtio_console: move removal code
commit aa44ec8 upstream. Will make it reusable for error handling. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent 0f26806 commit da1ced7

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

drivers/char/virtio_console.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,42 @@ static void remove_vqs(struct ports_device *portdev)
19801980
kfree(portdev->out_vqs);
19811981
}
19821982

1983+
static void virtcons_remove(struct virtio_device *vdev)
1984+
{
1985+
struct ports_device *portdev;
1986+
struct port *port, *port2;
1987+
1988+
portdev = vdev->priv;
1989+
1990+
spin_lock_irq(&pdrvdata_lock);
1991+
list_del(&portdev->list);
1992+
spin_unlock_irq(&pdrvdata_lock);
1993+
1994+
/* Disable interrupts for vqs */
1995+
vdev->config->reset(vdev);
1996+
/* Finish up work that's lined up */
1997+
if (use_multiport(portdev))
1998+
cancel_work_sync(&portdev->control_work);
1999+
else
2000+
cancel_work_sync(&portdev->config_work);
2001+
2002+
list_for_each_entry_safe(port, port2, &portdev->ports, list)
2003+
unplug_port(port);
2004+
2005+
unregister_chrdev(portdev->chr_major, "virtio-portsdev");
2006+
2007+
/*
2008+
* When yanking out a device, we immediately lose the
2009+
* (device-side) queues. So there's no point in keeping the
2010+
* guest side around till we drop our final reference. This
2011+
* also means that any ports which are in an open state will
2012+
* have to just stop using the port, as the vqs are going
2013+
* away.
2014+
*/
2015+
remove_vqs(portdev);
2016+
kfree(portdev);
2017+
}
2018+
19832019
/*
19842020
* Once we're further in boot, we get probed like any other virtio
19852021
* device.
@@ -2097,42 +2133,6 @@ static int virtcons_probe(struct virtio_device *vdev)
20972133
return err;
20982134
}
20992135

2100-
static void virtcons_remove(struct virtio_device *vdev)
2101-
{
2102-
struct ports_device *portdev;
2103-
struct port *port, *port2;
2104-
2105-
portdev = vdev->priv;
2106-
2107-
spin_lock_irq(&pdrvdata_lock);
2108-
list_del(&portdev->list);
2109-
spin_unlock_irq(&pdrvdata_lock);
2110-
2111-
/* Disable interrupts for vqs */
2112-
vdev->config->reset(vdev);
2113-
/* Finish up work that's lined up */
2114-
if (use_multiport(portdev))
2115-
cancel_work_sync(&portdev->control_work);
2116-
else
2117-
cancel_work_sync(&portdev->config_work);
2118-
2119-
list_for_each_entry_safe(port, port2, &portdev->ports, list)
2120-
unplug_port(port);
2121-
2122-
unregister_chrdev(portdev->chr_major, "virtio-portsdev");
2123-
2124-
/*
2125-
* When yanking out a device, we immediately lose the
2126-
* (device-side) queues. So there's no point in keeping the
2127-
* guest side around till we drop our final reference. This
2128-
* also means that any ports which are in an open state will
2129-
* have to just stop using the port, as the vqs are going
2130-
* away.
2131-
*/
2132-
remove_vqs(portdev);
2133-
kfree(portdev);
2134-
}
2135-
21362136
static struct virtio_device_id id_table[] = {
21372137
{ VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID },
21382138
{ 0 },

0 commit comments

Comments
 (0)