From: Jakob Koschel <jakobkoschel@gmail.com>
To: Fei Li <fei1.li@intel.com>
Cc: Jakob Koschel <jakobkoschel@gmail.com>,
linux-kernel@vger.kernel.org, Mike Rapoport <rppt@kernel.org>,
"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
Cristiano Giuffrida <c.giuffrida@vu.nl>,
"Bos, H.J." <h.j.bos@vu.nl>
Subject: [PATCH] virt: acrn: fix invalid check past list iterator
Date: Sat, 19 Mar 2022 21:38:19 +0100 [thread overview]
Message-ID: <20220319203819.2559993-1-jakobkoschel@gmail.com> (raw)
The condition retry == 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 <jakobkoschel@gmail.com>
---
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 = false;
unsigned long vcpu;
int retry = 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 = has_pending_request(client);
- if (has_pending)
+ client = NULL;
+ list_for_each_entry(iter, &vm->ioreq_clients, list) {
+ has_pending = has_pending_request(iter);
+ if (has_pending) {
+ client = iter;
break;
+ }
}
spin_unlock_bh(&vm->ioreq_clients_lock);
if (has_pending)
schedule_timeout_interruptible(HZ / 100);
} while (has_pending && --retry > 0);
- if (retry == 0)
+ if (client)
dev_warn(acrn_dev.this_device,
"%s cannot flush pending request!\n", client->name);
base-commit: 34e047aa16c0123bbae8e2f6df33e5ecc1f56601
--
2.25.1
next reply other threads:[~2022-03-19 20:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-19 20:38 Jakob Koschel [this message]
2022-03-30 7:57 ` Li Fei1
2022-03-31 11:20 ` Jakob Koschel
2022-04-01 1:15 ` Li Fei1
2022-04-01 3:22 ` Jakob Koschel
2022-04-01 3:57 ` Li Fei1
2022-04-01 7:16 ` Jakob Koschel
2022-04-01 7:57 ` Li Fei1
2022-04-01 8:50 ` Jakob Koschel
2022-04-01 9:05 ` Li Fei1
2022-04-01 9:08 ` Jakob Koschel
2022-04-01 9:12 ` Li Fei1
2022-04-01 9:24 ` Jakob Koschel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220319203819.2559993-1-jakobkoschel@gmail.com \
--to=jakobkoschel@gmail.com \
--cc=bjohannesmeyer@gmail.com \
--cc=c.giuffrida@vu.nl \
--cc=fei1.li@intel.com \
--cc=h.j.bos@vu.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®