All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	Gerd Hoffmann <kraxel@redhat.com>
Cc: Bug 1798780 <1798780@bugs.launchpad.net>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] usb-mtp: replace the homebrew write with qemu_write_full
Date: Tue, 22 Jan 2019 07:41:16 -0500	[thread overview]
Message-ID: <jpg8szcc1ar.fsf_-_@linux.bootlegged.copy> (raw)
In-Reply-To: <jpgd0ooc1f0.fsf@linux.bootlegged.copy> (Bandan Das's message of "Tue, 22 Jan 2019 07:38:43 -0500")


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

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Bandan <bsd@redhat.com>
---
 hw/usb/dev-mtp.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 31fa83589b..53e20e2161 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -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)
-- 
2.20.1

  reply	other threads:[~2019-01-22 18:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-19  9:07 [Qemu-devel] [Bug 1798780] [NEW] hw/usb/dev-mtp.c:1616: bad test ? dcb
2019-01-18 17:18 ` Peter Maydell
2019-01-22 12:38   ` Bandan Das
2019-01-22 12:41     ` Bandan Das [this message]
2019-01-24  8:01       ` [Qemu-devel] [PATCH] usb-mtp: replace the homebrew write with qemu_write_full Gerd Hoffmann
2019-01-24  8:19         ` Bandan Das
2019-01-24  8:31           ` Gerd Hoffmann
2019-04-24  6:07 ` [Qemu-devel] [Bug 1798780] Re: hw/usb/dev-mtp.c:1616: bad test ? Thomas Huth

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=jpg8szcc1ar.fsf_-_@linux.bootlegged.copy \
    --to=bsd@redhat.com \
    --cc=1798780@bugs.launchpad.net \
    --cc=kraxel@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.