Skip to contentSkip to conversation

qemu-char: check errno together with ret < 0

PATCH In review xinhua.Cao 5 participants 5 messages Jul 4, 2018

lore
Share & tools
lore

xinhua.Cao

author
#0 lore raw

PATCH 1/1 qemu-char: check errno together with ret < 0

In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred.
we need check errno together with ret < 0.

---
 chardev/char-socket.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
chardev/char-socket.c +5 -2
index 17519ec..efbad6e 100644
@@ -134,8 +134,11 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
                                         s->write_msgfds,
                                         s->write_msgfds_num);
 
-        /* free the written msgfds in any cases other than errno==EAGAIN */
-        if (EAGAIN != errno && s->write_msgfds_num) {
+        /* free the written msgfds in any cases
+         * other than ret < 0 && errno == EAGAIN
+         */
+        if (!(ret < 0 && EAGAIN == errno)
+            && s->write_msgfds_num) {
             g_free(s->write_msgfds);
             s->write_msgfds = 0;
             s->write_msgfds_num = 0;
Signature · 1 line
2.8.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · xinhua.Cao

In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred.
we need check errno together with ret < 0.

---
 chardev/char-socket.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
chardev/char-socket.c +0 -0
index 17519ec..efbad6e 100644
@@ -134,8 +134,11 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
                                         s->write_msgfds,
                                         s->write_msgfds_num);
 

chardev/char-socket.c static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len) · line 144

Quoted 10 lines
chardev/char-socket.c +5 -2
-        /* free the written msgfds in any cases other than errno==EAGAIN */
-        if (EAGAIN != errno && s->write_msgfds_num) {
+        /* free the written msgfds in any cases
+         * other than ret < 0 && errno == EAGAIN
+         */
+        if (!(ret < 0 && EAGAIN == errno)
+            && s->write_msgfds_num) {
             g_free(s->write_msgfds);
             s->write_msgfds = 0;
             s->write_msgfds_num = 0;

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/1
#2 lore raw
In reply to xinhua.Cao
Quoted 7 lines · xinhua.Cao

In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred.
we need check errno together with ret < 0.

Can you point out this is fixing commit 9fc53a10f81d3a9027b23fa810147d21be29e614 in commit message?

Quoted 27 lines
---
 chardev/char-socket.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
chardev/char-socket.c +5 -3
index 17519ec..efbad6e 100644
@@ -134,8 +134,11 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
                                         s->write_msgfds,
                                         s->write_msgfds_num);
 
-        /* free the written msgfds in any cases other than errno==EAGAIN */
-        if (EAGAIN != errno && s->write_msgfds_num) {
+        /* free the written msgfds in any cases
+         * other than ret < 0 && errno == EAGAIN
+         */
+        if (!(ret < 0 && EAGAIN == errno)
+            && s->write_msgfds_num) {
             g_free(s->write_msgfds);
             s->write_msgfds = 0;
             s->write_msgfds_num = 0;
--

2.8.3

Signature · 1 line
Marc-André Lureau
#3 lore raw
Quoted 7 lines · Marc-André Lureau
Quoted 6 lines · xinhua.Cao

In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred.
we need check errno together with ret < 0.

Quoted 5 lines
Quoted 1 line

Can you point out this is fixing commit 9fc53a10f81d3a9027b23fa810147d21be29e614 in commit message?

Ok, done.

Thanks,

Paolo

Quoted 32 lines
Quoted 27 lines
---
 chardev/char-socket.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
chardev/char-socket.c +5 -3
index 17519ec..efbad6e 100644
@@ -134,8 +134,11 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
                                         s->write_msgfds,
                                         s->write_msgfds_num);
 
-        /* free the written msgfds in any cases other than errno==EAGAIN */
-        if (EAGAIN != errno && s->write_msgfds_num) {
+        /* free the written msgfds in any cases
+         * other than ret < 0 && errno == EAGAIN
+         */
+        if (!(ret < 0 && EAGAIN == errno)
+            && s->write_msgfds_num) {
             g_free(s->write_msgfds);
             s->write_msgfds = 0;
             s->write_msgfds_num = 0;
--

2.8.3

#4 lore raw
In reply to xinhua.Cao
Quoted 19 lines · xinhua.Cao

In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred.
we need check errno together with ret < 0.

---
 chardev/char-socket.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
chardev/char-socket.c +0 -0
index 17519ec..efbad6e 100644
@@ -134,8 +134,11 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
                                         s->write_msgfds,
                                         s->write_msgfds_num);
 

chardev/char-socket.c static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len) · line 144

Quoted 10 lines
chardev/char-socket.c +5 -2
-        /* free the written msgfds in any cases other than errno==EAGAIN */
-        if (EAGAIN != errno && s->write_msgfds_num) {
+        /* free the written msgfds in any cases
+         * other than ret < 0 && errno == EAGAIN
+         */
+        if (!(ret < 0 && EAGAIN == errno)
+            && s->write_msgfds_num) {
             g_free(s->write_msgfds);
             s->write_msgfds = 0;
             s->write_msgfds_num = 0;

The comment feels pretty worthless to me.