From nobody Mon Jun 22 16:54:33 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 62025C433EF for ; Sat, 19 Mar 2022 20:38:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244162AbiCSUj5 (ORCPT ); Sat, 19 Mar 2022 16:39:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232685AbiCSUjx (ORCPT ); Sat, 19 Mar 2022 16:39:53 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62BFF197F8E for ; Sat, 19 Mar 2022 13:38:31 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id r22so2959289ejs.11 for ; Sat, 19 Mar 2022 13:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5yDAY6CmvNAdYPiLE5j66Po7nzSgQMLanAVyEQyO52M=; b=Qu56kVuio6f+jRUuV5b5iTfhX4+BP/y8VAB3iBJbvzGTJkSkWOaBi6MmKnH/3Eu7Ji 6uuRG7NHsyjLcBHYL5er6sB0bTszm/Id7or1yQJpZLzZkLkbWGhkUBcWLT+TMfEMrtgA 0qJm3uBPkU274N93jmsjq9uwNhW86WlKOxRu+LABinitxkicnz2GtY1pHSLoyxGD2+3a REtWo4UzOFXQ666cr3X7c0osYeKRYrpsuG+OgBefrSuN2B/l3qhLjB8ue6HuX0z2vxX8 ZtiKZluvAy29mF51s5MNUoPt5lecK2ZB2zUIHEFUpmVc4E44TPX20XYkWfF2HCo+KHlf 1nnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5yDAY6CmvNAdYPiLE5j66Po7nzSgQMLanAVyEQyO52M=; b=hnEBHav6Am/iiHFsRzBesGiaInnip0fKPpIvyMt9qEdJ6oek55v8DpWENy9L66S+/J TyKVQTWo9TyWPYL0hpdBIUR/ydqPe0KUZUEUCAzeiRAQCm1H6H98ikuwOtRGihATjPJT QStT2yBiaBvsG4VGztz6Jztp61yP+Oasy+YD1NRgqQB0uzAjnzz1kZt04y1JRkfjAhLV 5ax0QbZtZK//H5yz1l5SSSSe3nsdVNGERkhrDJPP/6+4r0b3epp/mxDEnmM6zsd+4lF/ TCKcGF9vXyI/0DzfWdfltUbXAVps4K3V6LbH0NsYatcZ2v2M3kUsYWJk/WwCw8Nr8QWi gSQg== X-Gm-Message-State: AOAM531qYzFkjs/cNcs+luy4Srqe9yCiG7hbfpH3lz5eKgsmLIfUI1Me 57jZazpLXXRqKDGox6wTikM= X-Google-Smtp-Source: ABdhPJyWxAEUuOiZy6bVW4XMk+eVooJFyZH21j3Xd/9Gl2LbqV14uONHRevzcjGBWYX2qj7v3G+8ww== X-Received: by 2002:a17:907:1b1e:b0:6d7:31b0:e821 with SMTP id mp30-20020a1709071b1e00b006d731b0e821mr14432056ejc.334.1647722309966; Sat, 19 Mar 2022 13:38:29 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id k7-20020aa7c047000000b004132d3b60aasm5888884edo.78.2022.03.19.13.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 13:38:29 -0700 (PDT) From: Jakob Koschel To: Fei Li Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH] virt: acrn: fix invalid check past list iterator Date: Sat, 19 Mar 2022 21:38:19 +0100 Message-Id: <20220319203819.2559993-1-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The condition retry =3D=3D 0 is theoretically possible even if 'client' does not point to a valid element because no break was hit. To only execute the dev_warn if actually a break within the loop was hit, a separate variable is used that is only set if it is ensured to point to a valid client struct. Signed-off-by: Jakob Koschel --- drivers/virt/acrn/ioreq.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/virt/acrn/ioreq.c b/drivers/virt/acrn/ioreq.c index 5ff1c53740c0..bdf7cedce926 100644 --- a/drivers/virt/acrn/ioreq.c +++ b/drivers/virt/acrn/ioreq.c @@ -211,7 +211,7 @@ static int ioreq_task(void *data) */ void acrn_ioreq_request_clear(struct acrn_vm *vm) { - struct acrn_ioreq_client *client; + struct acrn_ioreq_client *client, *iter; bool has_pending =3D false; unsigned long vcpu; int retry =3D 10; @@ -228,17 +228,20 @@ void acrn_ioreq_request_clear(struct acrn_vm *vm) */ do { spin_lock_bh(&vm->ioreq_clients_lock); - list_for_each_entry(client, &vm->ioreq_clients, list) { - has_pending =3D has_pending_request(client); - if (has_pending) + client =3D NULL; + list_for_each_entry(iter, &vm->ioreq_clients, list) { + has_pending =3D has_pending_request(iter); + if (has_pending) { + client =3D iter; break; + } } spin_unlock_bh(&vm->ioreq_clients_lock); if (has_pending) schedule_timeout_interruptible(HZ / 100); } while (has_pending && --retry > 0); - if (retry =3D=3D 0) + if (client) dev_warn(acrn_dev.this_device, "%s cannot flush pending request!\n", client->name); base-commit: 34e047aa16c0123bbae8e2f6df33e5ecc1f56601 -- 2.25.1