Skip to contentSkip to conversation

hw/usb/dev-mtp.c:1616: bad test ?

Qemu-devel In review dcb 4 participants 8 messages Oct 19, 2018 – Apr 24, 2019

lore
Share & tools
lore

dcb

author
#0 lore raw

Public bug reported:

hw/usb/dev-mtp.c:1616:52: warning: logical ‘or’ of collectively exhaustive tests is always true [-Wlogical-op]

Source code is

                if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
                                    errno != EWOULDBLOCK)) {

Maybe better code

                if ((ret == -1) && (errno != EINTR && errno != EAGAIN &&
                                    errno != EWOULDBLOCK)) {

** Affects: qemu
Importance: Undecided
Status: New

Signature · 26 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1798780

Title:
  hw/usb/dev-mtp.c:1616: bad test ?

Status in QEMU:
  New

Bug description:
  hw/usb/dev-mtp.c:1616:52: warning: logical ‘or’ of collectively
  exhaustive tests is always true [-Wlogical-op]

  Source code is

                  if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
                                      errno != EWOULDBLOCK)) {

  Maybe better code

                  if ((ret == -1) && (errno != EINTR && errno != EAGAIN &&
                                      errno != EWOULDBLOCK)) {

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1798780/+subscriptions
#1 lore raw
Quoted 5 lines · dcb

hw/usb/dev-mtp.c:1616:52: warning: logical ‘or’ of collectively exhaustive tests is always true [-Wlogical-op]

Source code is

Quoted 7 lines
                if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
                                    errno != EWOULDBLOCK)) {

Maybe better code

                if ((ret == -1) && (errno != EINTR && errno != EAGAIN &&
                                    errno != EWOULDBLOCK)) {

Hi Gerd, Bandan -- I was going through older launchpad bugs and noticed that this one about a dubious conditional in dev-mtp.c is still unfixed.

Is the file descriptor being used here one that's in non-blocking mode? If so, then busy-waiting in a loop while the write() returns EWOULDBLOCK is probably not what you wanted. If it's not then there's no need to check for EAGAIN or EWOULDBLOCK, I think. Consider using qemu_write_full() instead of open-coding the retry loop ?

thanks
-- PMM

#2 lore raw
Quoted 18 lines · Peter Maydell
Quoted 5 lines · dcb

hw/usb/dev-mtp.c:1616:52: warning: logical ‘or’ of collectively exhaustive tests is always true [-Wlogical-op]

Source code is

Quoted 7 lines
                if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
                                    errno != EWOULDBLOCK)) {

Maybe better code

                if ((ret == -1) && (errno != EINTR && errno != EAGAIN &&
                                    errno != EWOULDBLOCK)) {

Hi Gerd, Bandan -- I was going through older launchpad bugs and noticed that this one about a dubious conditional in dev-mtp.c is still unfixed.

Quoted 7 lines

Is the file descriptor being used here one that's in non-blocking mode? If so, then busy-waiting in a loop while the write() returns EWOULDBLOCK is probably not what you wanted. If it's not then there's no need to check for EAGAIN or EWOULDBLOCK, I think. Consider using qemu_write_full() instead of open-coding the retry loop ?

Thanks for the suggestion, Peter. I agree, this isn't non-blocking and qemu_write_full() can be used. Following up with a patch.

Bandan

Quoted 2 lines

thanks
-- PMM

#3 lore raw

PATCH 1/1 usb-mtp: replace the homebrew write with qemu_write_full

qemu_write_full takes care of partial blocking writes, as in cases of larger file sizes

---
 hw/usb/dev-mtp.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
hw/usb/dev-mtp.c +3 -11
index 31fa83589b..53e20e2161 100644
@@ -1630,25 +1630,16 @@ static char *utf16_to_str(uint8_t len, uint16_t *arr)
 /* Wrapper around write, returns 0 on failure */
 static uint64_t write_retry(int fd, void *buf, uint64_t size, off_t offset)
 {
-        uint64_t bytes_left = size, ret;
+        uint64_t ret = 0;
 
         if (lseek(fd, offset, SEEK_SET) < 0) {
             goto done;
         }
 
-        while (bytes_left > 0) {
-                ret = write(fd, buf, bytes_left);
-                if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
-                                    errno != EWOULDBLOCK)) {
-                        break;
-                }
-                bytes_left -= ret;
-                buf += ret;
-        }
+        ret = qemu_write_full(fd, buf, size);
 
 done:
-        return size - bytes_left;
+        return ret;
 }
 
 static void usb_mtp_update_object(MTPObject *parent, char *name)
Signature · 1 line
2.20.1
#4 lore raw

Re: [Qemu-devel] [PATCH] usb-mtp: replace the homebrew write with qemu_write_full

Quoted 6 lines · Bandan Das

qemu_write_full takes care of partial blocking writes, as in cases of larger file sizes

Hmm, doesn't apply, and git fails to do a 3way merge too due to unknown sha1.

cheers,
Gerd

#5 lore raw

Re: [Qemu-devel] [PATCH] usb-mtp: replace the homebrew write with qemu_write_full

Quoted 11 lines · Gerd Hoffmann
Quoted 6 lines · Bandan Das

qemu_write_full takes care of partial blocking writes, as in cases of larger file sizes

Hmm, doesn't apply, and git fails to do a 3way merge too due to unknown sha1.

Oops, sorry, I realize now this is on top of the write buffer breakup patches.

Should I resend a v2 on top of master and send a v3 for the write buffer breakup patches ?

Quoted 2 lines

cheers,
Gerd

#6 lore raw

Re: [Qemu-devel] [PATCH] usb-mtp: replace the homebrew write with qemu_write_full

Quoted 7 lines · Bandan Das
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Bandan Das

qemu_write_full takes care of partial blocking writes, as in cases of larger file sizes

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Hmm, doesn't apply, and git fails to do a 3way merge too due to unknown sha1.

Oops, sorry, I realize now this is on top of the write buffer breakup patches.

Hmm, they are queued up already, so that should have worked.

Quoted 2 lines

Should I resend a v2 on top of master and send a v3 for the write buffer breakup patches ?

Can you just send a single series with both this fix and the breakup patches, against latest master?

thanks,
Gerd

#7 lore raw
In reply to dcb

** Changed in: qemu
Status: Fix Committed => Fix Released

Signature · 26 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1798780

Title:
  hw/usb/dev-mtp.c:1616: bad test ?

Status in QEMU:
  Fix Released

Bug description:
  hw/usb/dev-mtp.c:1616:52: warning: logical ‘or’ of collectively
  exhaustive tests is always true [-Wlogical-op]

  Source code is

                  if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
                                      errno != EWOULDBLOCK)) {

  Maybe better code

                  if ((ret == -1) && (errno != EINTR && errno != EAGAIN &&
                                      errno != EWOULDBLOCK)) {

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1798780/+subscriptions