From nobody Tue Apr 28 23:19:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D2F0C433EF for ; Fri, 27 May 2022 01:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232648AbiE0Bga (ORCPT ); Thu, 26 May 2022 21:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbiE0Bg0 (ORCPT ); Thu, 26 May 2022 21:36:26 -0400 X-Greylist: delayed 125 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 26 May 2022 18:36:23 PDT Received: from ssh248.corpemail.net (ssh248.corpemail.net [210.51.61.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB4F729CBE for ; Thu, 26 May 2022 18:36:21 -0700 (PDT) Received: from ([60.208.111.195]) by ssh248.corpemail.net ((D)) with ASMTP (SSL) id VWJ00111; Fri, 27 May 2022 09:34:11 +0800 Received: from localhost.localdomain (10.200.104.97) by jtjnmail201603.home.langchao.com (10.100.2.3) with Microsoft SMTP Server id 15.1.2308.27; Fri, 27 May 2022 09:34:10 +0800 From: Bo Liu To: , , CC: , , Bo Liu Subject: [PATCH] virtio_balloon: check virtqueue_add_outbuf() return value Date: Thu, 26 May 2022 21:34:01 -0400 Message-ID: <20220527013401.2196-1-liubo03@inspur.com> X-Mailer: git-send-email 2.18.2 MIME-Version: 1.0 X-Originating-IP: [10.200.104.97] tUid: 202252709341106a152b69564d3472b2363ee94035093 X-Abuse-Reports-To: service@corp-email.com Abuse-Reports-To: service@corp-email.com X-Complaints-To: service@corp-email.com X-Report-Abuse-To: service@corp-email.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" virtqueue_add_outbuf() can fail, when it fails, there is no need to call the funciont virtqueue_kick(). Signed-off-by: Bo Liu --- drivers/virtio/virtio_balloon.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index b9737da6c4dd..0d7da4d95e1e 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -153,16 +153,18 @@ static void tell_host(struct virtio_balloon *vb, stru= ct virtqueue *vq) { struct scatterlist sg; unsigned int len; + int err; =20 sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); =20 /* We should always be able to add one buffer to an empty queue. */ - virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); - virtqueue_kick(vq); - - /* When host has read buffer, this completes via balloon_ack */ - wait_event(vb->acked, virtqueue_get_buf(vq, &len)); + err =3D virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); + if (!err) { + virtqueue_kick(vq); =20 + /* When host has read buffer, this completes via balloon_ack */ + wait_event(vb->acked, virtqueue_get_buf(vq, &len)); + } } =20 static int virtballoon_free_page_report(struct page_reporting_dev_info *pr= _dev_info, @@ -382,6 +384,7 @@ static void stats_handle_request(struct virtio_balloon = *vb) struct virtqueue *vq; struct scatterlist sg; unsigned int len, num_stats; + int err; =20 num_stats =3D update_balloon_stats(vb); =20 @@ -389,8 +392,9 @@ static void stats_handle_request(struct virtio_balloon = *vb) if (!virtqueue_get_buf(vq, &len)) return; sg_init_one(&sg, vb->stats, sizeof(vb->stats[0]) * num_stats); - virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); - virtqueue_kick(vq); + err =3D virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); + if (!err) + virtqueue_kick(vq); } =20 static inline s64 towards_target(struct virtio_balloon *vb) --=20 2.27.0