Received: by 10.192.165.148 with SMTP id m20csp567452imm; Fri, 20 Apr 2018 11:20:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+EuFc0LPqlGqf5DSLMtTxuQG3rb8xE8O9v5irbtK0cHLCvsieE4M/TgZcT3DmMB0dsEM2a X-Received: by 10.99.42.206 with SMTP id q197mr9498901pgq.60.1524248402352; Fri, 20 Apr 2018 11:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524248402; cv=none; d=google.com; s=arc-20160816; b=PqvNacgq9EBXtcHvVZewjg6JDrIJEm5tIdl4xgGPXs6H9OJ+BxOTMC8K8rpUeKG+SN Q3XfK3UZJCR0rEyJBqWtM3PaD4Yvs+7U99ycsVhkj/Y6mEUp4sKKzU5BxmChxo4naILC +fpF9hkAZF4Wl14bC42GmXmSTA7zi5UIDIom3IINaAZUpNlZGzQV9OP0ddpTa6J0w8wC 3Yicuuv9pn7yTM9jGfm9ZAFJ4URTUXfj8i2Au8SS/Ob1VGve6Kt9eXo10FkGSlTe/0EL eXaNPnPaqjKosRMs7urZjtq1dnHwC0+5jdsOiERSXV/V8arXaFLFCEqa3VT29AKbwKXZ cxIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=MxsH4c5diKRNF/YZQYFPgPwmdNDbQbJLXCGlj75UcgQ=; b=dVrjLSR3N/83+tfkHfcCAC2G3Zn+3o2IC77ORGo8mOLatjQUJscw4kpgsLc34sgF7J v/WqBkdOIksRuJl9WKW1XCjmQeyRXwFymjg59p5fZtQAwqDJLF6fantGmthfOKmQmFLT 3fZvDi+L5bA/zSHAbBk5rpUVW9oIW1NeO3H83OuKbOXL/dkqi+4lQbMv3IJZGZERMeAD 7ifBln7CWMV32nxVaoGm4DMuqza1d6KfAtYcObCWxY0CSzZnbz6ISivGNqnIuF8Oxne2 G6ZV2GYt0oNdhJX+XOygNboAW4bhgABnKXgAruOLeDXmF6eHpn2Cwr3BvXkjiqDaA18b ok3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si6116931pld.69.2018.04.20.11.19.48; Fri, 20 Apr 2018 11:20:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753833AbeDTSSK (ORCPT + 99 others); Fri, 20 Apr 2018 14:18:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60668 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753706AbeDTSSG (ORCPT ); Fri, 20 Apr 2018 14:18:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20C8A4023159; Fri, 20 Apr 2018 18:18:06 +0000 (UTC) Received: from redhat.com (ovpn-126-37.rdu2.redhat.com [10.10.126.37]) by smtp.corp.redhat.com (Postfix) with SMTP id 9C19994582; Fri, 20 Apr 2018 18:18:05 +0000 (UTC) Date: Fri, 20 Apr 2018 21:18:05 +0300 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Amit Shah , Arnd Bergmann , Greg Kroah-Hartman , virtualization@lists.linux-foundation.org, stable@vger.kernel.org, Tiwei Bie , Jason Wang Subject: [PATCH 5/6] virtio_console: move removal code Message-ID: <1524248223-393618-6-git-send-email-mst@redhat.com> References: <1524248223-393618-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1524248223-393618-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 20 Apr 2018 18:18:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 20 Apr 2018 18:18:06 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Will make it reusable for error handling. Signed-off-by: Michael S. Tsirkin --- drivers/char/virtio_console.c | 72 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 2d87ce5..e8480fe 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -1988,6 +1988,42 @@ static void remove_vqs(struct ports_device *portdev) kfree(portdev->out_vqs); } +static void virtcons_remove(struct virtio_device *vdev) +{ + struct ports_device *portdev; + struct port *port, *port2; + + portdev = vdev->priv; + + spin_lock_irq(&pdrvdata_lock); + list_del(&portdev->list); + spin_unlock_irq(&pdrvdata_lock); + + /* Disable interrupts for vqs */ + vdev->config->reset(vdev); + /* Finish up work that's lined up */ + if (use_multiport(portdev)) + cancel_work_sync(&portdev->control_work); + else + cancel_work_sync(&portdev->config_work); + + list_for_each_entry_safe(port, port2, &portdev->ports, list) + unplug_port(port); + + unregister_chrdev(portdev->chr_major, "virtio-portsdev"); + + /* + * When yanking out a device, we immediately lose the + * (device-side) queues. So there's no point in keeping the + * guest side around till we drop our final reference. This + * also means that any ports which are in an open state will + * have to just stop using the port, as the vqs are going + * away. + */ + remove_vqs(portdev); + kfree(portdev); +} + /* * Once we're further in boot, we get probed like any other virtio * device. @@ -2116,42 +2152,6 @@ static int virtcons_probe(struct virtio_device *vdev) return err; } -static void virtcons_remove(struct virtio_device *vdev) -{ - struct ports_device *portdev; - struct port *port, *port2; - - portdev = vdev->priv; - - spin_lock_irq(&pdrvdata_lock); - list_del(&portdev->list); - spin_unlock_irq(&pdrvdata_lock); - - /* Disable interrupts for vqs */ - vdev->config->reset(vdev); - /* Finish up work that's lined up */ - if (use_multiport(portdev)) - cancel_work_sync(&portdev->control_work); - else - cancel_work_sync(&portdev->config_work); - - list_for_each_entry_safe(port, port2, &portdev->ports, list) - unplug_port(port); - - unregister_chrdev(portdev->chr_major, "virtio-portsdev"); - - /* - * When yanking out a device, we immediately lose the - * (device-side) queues. So there's no point in keeping the - * guest side around till we drop our final reference. This - * also means that any ports which are in an open state will - * have to just stop using the port, as the vqs are going - * away. - */ - remove_vqs(portdev); - kfree(portdev); -} - static struct virtio_device_id id_table[] = { { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, { 0 }, -- MST