Skip to contentSkip to conversation

chardev/char: fix qemu_chr_is_busy() check

PATCH In review Roman Penyaev 2 participants 4 messages Oct 10, 2024 – Oct 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chardev/char: fix qemu_chr_is_busy() check

mux_cnt struct member never goes negative or decrements, so mux chardev can be !busy only when there are no frontends attached. This patch fixes the always-true check.

Fixes a4afa548fc6d ("char: move front end handlers in CharBackend")
Cc "Marc-André Lureau" <[email protected]>
---
 chardev/char.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char.c +1 -1
index c0cc52824b48..f54dc3a86286 100644
@@ -333,7 +333,7 @@ static bool qemu_chr_is_busy(Chardev *s)
 {
     if (CHARDEV_IS_MUX(s)) {
         MuxChardev *d = MUX_CHARDEV(s);
-        return d->mux_cnt >= 0;
+        return d->mux_cnt > 0;
     } else {
         return s->be != NULL;
     }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Roman

Quoted 9 lines · Roman Penyaev

mux_cnt struct member never goes negative or decrements, so mux chardev can be !busy only when there are no frontends attached. This patch fixes the always-true check.

Fixes a4afa548fc6d ("char: move front end handlers in CharBackend")
Cc "Marc-André Lureau" <[email protected]>

That would be worth some new tests for chardev removal. It seems to be lacking. And mux probably need extra fixing. I can take a look if you don't.

thanks

Quoted 22 lines
---
 chardev/char.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char.c +1 -2
index c0cc52824b48..f54dc3a86286 100644
@@ -333,7 +333,7 @@ static bool qemu_chr_is_busy(Chardev *s)
 {
     if (CHARDEV_IS_MUX(s)) {
         MuxChardev *d = MUX_CHARDEV(s);
-        return d->mux_cnt >= 0;
+        return d->mux_cnt > 0;
     } else {
         return s->be != NULL;
     }
--

2.34.1

Signature · 1 line
Marc-André Lureau
#2 lore raw
Quoted 15 lines · On Thu, Oct 10, 2024, 12:20 Marc-André Lureau <[email protected]>…

Hi Roman

Quoted 9 lines · Roman Penyaev

mux_cnt struct member never goes negative or decrements, so mux chardev can be !busy only when there are no frontends attached. This patch fixes the always-true check.

Fixes a4afa548fc6d ("char: move front end handlers in CharBackend")
Cc "Marc-André Lureau" <[email protected]>
Quoted 5 lines

That would be worth some new tests for chardev removal. It seems to be lacking. And mux probably need extra fixing. I can take a look if you don't.

I assume no one removes mux device, so no one observes the error. Please, go ahead, I'm not sure I do fully understand what exactly should be fixed.

--
Roman

#3 lore raw
In reply to Marc-André Lureau

Hi Marc-André,

Quoted 16 lines · Marc-André Lureau

Hi Roman

Quoted 10 lines · Roman Penyaev

mux_cnt struct member never goes negative or decrements, so mux chardev can be !busy only when there are no frontends attached. This patch fixes the always-true check.

Fixes a4afa548fc6d ("char: move front end handlers in CharBackend")
Cc "Marc-André Lureau" <[email protected]>
Quoted 3 lines

That would be worth some new tests for chardev removal. It seems to be lacking. And mux probably need extra fixing. I can take a look if you don't.

I've just sent an attempt to fix the removal of frontends, plus some test cases. Please take a look.

Thanks.

--
Roman