From nobody Fri Nov 7 10:18:16 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548182989700675.2630530186536; Tue, 22 Jan 2019 10:49:49 -0800 (PST) Received: from localhost ([127.0.0.1]:47164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm17L-00060k-CP for importer@patchew.org; Tue, 22 Jan 2019 13:49:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm11B-000157-RJ for qemu-devel@nongnu.org; Tue, 22 Jan 2019 13:43:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm113-0002fW-Am for qemu-devel@nongnu.org; Tue, 22 Jan 2019 13:43:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gm10v-0001Yv-NV for qemu-devel@nongnu.org; Tue, 22 Jan 2019 13:43:11 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D420189ACB; Tue, 22 Jan 2019 12:41:17 +0000 (UTC) Received: from gigantic.usersys.redhat.com (helium.bos.redhat.com [10.18.17.132]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4234B608F3; Tue, 22 Jan 2019 12:41:17 +0000 (UTC) From: Bandan Das To: Peter Maydell , Gerd Hoffmann References: <153994006052.15678.15962440455123359491.malonedeb@gac.canonical.com> Date: Tue, 22 Jan 2019 07:41:16 -0500 In-Reply-To: (Bandan Das's message of "Tue, 22 Jan 2019 07:38:43 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 22 Jan 2019 12:41:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] usb-mtp: replace the homebrew write with qemu_write_full X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bug 1798780 <1798780@bugs.launchpad.net>, QEMU Developers Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" qemu_write_full takes care of partial blocking writes, as in cases of larger file sizes Suggested-by: Peter Maydell Signed-off-by: Bandan --- 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 *ar= r) /* 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 =3D size, ret; + uint64_t ret =3D 0; =20 if (lseek(fd, offset, SEEK_SET) < 0) { goto done; } =20 - while (bytes_left > 0) { - ret =3D write(fd, buf, bytes_left); - if ((ret =3D=3D -1) && (errno !=3D EINTR || errno !=3D EAG= AIN || - errno !=3D EWOULDBLOCK)) { - break; - } - bytes_left -=3D ret; - buf +=3D ret; - } + ret =3D qemu_write_full(fd, buf, size); =20 done: - return size - bytes_left; + return ret; } =20 static void usb_mtp_update_object(MTPObject *parent, char *name) --=20 2.20.1