From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaSkj-00024R-GS for qemu-devel@nongnu.org; Mon, 29 Feb 2016 13:41:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaSki-0007sY-4u for qemu-devel@nongnu.org; Mon, 29 Feb 2016 13:41:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaSkh-0007sC-Vf for qemu-devel@nongnu.org; Mon, 29 Feb 2016 13:41:04 -0500 From: Markus Armbruster Date: Mon, 29 Feb 2016 19:40:47 +0100 Message-Id: <1456771254-17511-32-git-send-email-armbru@redhat.com> In-Reply-To: <1456771254-17511-1-git-send-email-armbru@redhat.com> References: <1456771254-17511-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH 31/38] 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 Cc: claudio.fontana@huawei.com, cam@cs.ualberta.ca, mlureau@redhat.com, david.marchand@6wind.com, pbonzini@redhat.com Improve the error messages while there. Signed-off-by: Markus Armbruster --- 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 0440bca..785ed1c 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -342,29 +342,6 @@ static void watch_vector_notifier(IVShmemState *s, EventNotifier *n, NULL, &s->msi_vectors[vector]); } -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, @@ -479,7 +456,7 @@ static void setup_interrupt(IVShmemState *s, int vector, Error **errp) static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) { - Error *err = NULL; + struct stat buf; void *ptr; if (s->ivshmem_bar2) { @@ -488,8 +465,16 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) return; } - if (check_shm_size(s, fd, &err) == -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; } -- 2.4.3