Received: from eggs.gnu.org ([2001:4830:134:3::10]:48804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai6gS-0000U0-WA for qemu-devel@nongnu.org; Mon, 21 Mar 2016 16:44:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ai6gP-0000oy-Hg for qemu-devel@nongnu.org; Mon, 21 Mar 2016 16:44:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai6gP-0000oN-BX for qemu-devel@nongnu.org; Mon, 21 Mar 2016 16:44:13 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id EA0ED804EF for ; Mon, 21 Mar 2016 20:44:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2LKi9HH015188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 21 Mar 2016 16:44:12 -0400 From: Markus Armbruster Date: Mon, 21 Mar 2016 21:43:56 +0100 Message-Id: <1458593043-31731-34-git-send-email-armbru@redhat.com> In-Reply-To: <1458593043-31731-1-git-send-email-armbru@redhat.com> References: <1458593043-31731-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL v2 33/40] ivshmem: Inline check_shm_size() into its only caller List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Improve the error messages while there. Signed-off-by: Markus Armbruster Message-Id: <1458066895-20632-34-git-send-email-armbru@redhat.com> Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/misc/ivshmem.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 1b1de65..e6282ab 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -343,29 +343,6 @@ static void watch_vector_notifier(IVShmemState *s, E= ventNotifier *n, NULL, &s->msi_vectors[vector]); } =20 -static int check_shm_size(IVShmemState *s, int fd, Error **errp) -{ - /* check that the guest isn't going to try and map more memory than = the - * the object has allocated return -1 to indicate error */ - - struct stat buf; - - if (fstat(fd, &buf) < 0) { - error_setg(errp, "exiting: fstat on fd %d failed: %s", - fd, strerror(errno)); - return -1; - } - - if (s->ivshmem_size > buf.st_size) { - error_setg(errp, "Requested memory size greater" - " than shared object size (%zu > %" PRIu64")", - s->ivshmem_size, (uint64_t)buf.st_size); - return -1; - } else { - return 0; - } -} - static void ivshmem_add_eventfd(IVShmemState *s, int posn, int i) { memory_region_add_eventfd(&s->ivshmem_mmio, @@ -480,7 +457,7 @@ static void setup_interrupt(IVShmemState *s, int vect= or, Error **errp) =20 static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) { - Error *err =3D NULL; + struct stat buf; void *ptr; =20 if (s->ivshmem_bar2) { @@ -489,8 +466,16 @@ static void process_msg_shmem(IVShmemState *s, int f= d, Error **errp) return; } =20 - if (check_shm_size(s, fd, &err) =3D=3D -1) { - error_propagate(errp, err); + if (fstat(fd, &buf) < 0) { + error_setg_errno(errp, errno, + "can't determine size of shared memory sent by server"); + close(fd); + return; + } + + if (s->ivshmem_size > buf.st_size) { + error_setg(errp, "server sent only %zd bytes of shared memory", + (size_t)buf.st_size); close(fd); return; } --=20 2.4.3