Received: by 10.192.165.148 with SMTP id m20csp4157600imm; Mon, 30 Apr 2018 12:52:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdNoEMouox2nPfbn8net2U2qAkJ4HWEl9zm1ik8tG7N1f/3pbgbZF7PvS7Us6HUE1KaEbN X-Received: by 2002:a63:790e:: with SMTP id u14-v6mr11115156pgc.445.1525117959124; Mon, 30 Apr 2018 12:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117959; cv=none; d=google.com; s=arc-20160816; b=QgCS4PeFM4gNE1YdLaWv6VQGcA5yaoXLHHnDnfUvK0RzIhw6ilbCcx/le3A8110l2q 2OmK9PRu66d77v7h9P7n8HDZdPNEeyXkQbFAx+VFjqk53696wupfemBuvXY0io8xwV3Q gL93xEKHt8f0WbAn4e4b/rDKemD5IIOzoHKaT2L44YMFILMZoPlGDa61Kqf8f/1vkV44 zSgMT4GwkIaZ3kPo6YIlykBqEtZstPW/bxYY6TVDjefPnp6oiJzGbJyA0vX/dzJDmRU7 VpRv/Yt+lvPQMwze4xDQr1SDqm9Y++NdSowrGSivC+nYdeF8NJ/6XDgroEmdHCViw9sN thIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=uEviXIEgEG6jcyycmsGEGgH2r7VKFIhoKcYQhefil7E=; b=0l4mj1Xo7flnHPSBjdmEuEMrNfhyXZbs5+uJJVnwB/JB9UtZjqoJ7kXegSl/rQ0Req 3e37xXAzwonPFCIpJQuJAzIwpiZbPPzaQCz4tIyV1aUgIhPraO6WTYF/i6b9Hp6PK4yQ IZeh755m/0FYSjRJ7lTZW1ZelU4H9xOh8IN7XXi1GjsYJwEZ3pcq/VCIZmU2zM12Aek+ sethJGmhozVxMdsG3JXJUXUGfbEbBawutlKXlSlGuMLLQSDlAzT9cV5xNehfMTQn+qe/ duMw2TQJZRKoQI6ar1zIntvk48ppUcHAJoAUIFGhVhSR+slxlSc/O9LLyXvjT8IuEZJJ k87A== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3-v6si7820840plb.536.2018.04.30.12.52.25; Mon, 30 Apr 2018 12:52:39 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755448AbeD3Tvd (ORCPT + 99 others); Mon, 30 Apr 2018 15:51:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:35368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754903AbeD3T2F (ORCPT ); Mon, 30 Apr 2018 15:28:05 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6541E22DBF; Mon, 30 Apr 2018 19:28:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6541E22DBF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael S. Tsirkin" Subject: [PATCH 4.16 029/113] virtio_console: reset on out of memory Date: Mon, 30 Apr 2018 12:24:00 -0700 Message-Id: <20180430184016.306577052@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael S. Tsirkin commit 5c60300d68da32ca77f7f978039dc72bfc78b06b upstream. When out of memory and we can't add ctrl vq buffers, probe fails. Unfortunately the error handling is out of spec: it calls del_vqs without bothering to reset the device first. To fix, call the full cleanup function in this case. Cc: stable@vger.kernel.org Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/char/virtio_console.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -2090,6 +2090,7 @@ static int virtcons_probe(struct virtio_ spin_lock_init(&portdev->ports_lock); INIT_LIST_HEAD(&portdev->ports); + INIT_LIST_HEAD(&portdev->list); virtio_device_ready(portdev->vdev); @@ -2107,8 +2108,15 @@ static int virtcons_probe(struct virtio_ if (!nr_added_bufs) { dev_err(&vdev->dev, "Error allocating buffers for control queue\n"); - err = -ENOMEM; - goto free_vqs; + /* + * The host might want to notify mgmt sw about device + * add failure. + */ + __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, + VIRTIO_CONSOLE_DEVICE_READY, 0); + /* Device was functional: we need full cleanup. */ + virtcons_remove(vdev); + return -ENOMEM; } } else { /* @@ -2139,11 +2147,6 @@ static int virtcons_probe(struct virtio_ return 0; -free_vqs: - /* The host might want to notify mgmt sw about device add failure */ - __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, - VIRTIO_CONSOLE_DEVICE_READY, 0); - remove_vqs(portdev); free_chrdev: unregister_chrdev(portdev->chr_major, "virtio-portsdev"); free: