From patchwork Mon Mar 7 19:25:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8522441 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BFC7EC0553 for ; Mon, 7 Mar 2016 19:46:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3161220114 for ; Mon, 7 Mar 2016 19:46:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 65DEE2014A for ; Mon, 7 Mar 2016 19:46:05 +0000 (UTC) Received: from localhost ([::1]:58114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad16S-0005VS-Sv for patchwork-qemu-devel@patchwork.kernel.org; Mon, 07 Mar 2016 14:46:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad0nA-0004C3-VR for qemu-devel@nongnu.org; Mon, 07 Mar 2016 14:26:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ad0n8-00040b-LF for qemu-devel@nongnu.org; Mon, 07 Mar 2016 14:26:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad0n8-00040E-Ex for qemu-devel@nongnu.org; Mon, 07 Mar 2016 14:26:06 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 21CE93298; Mon, 7 Mar 2016 19:26:06 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-61.ams2.redhat.com [10.36.116.61]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u27JQ3dG031113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 7 Mar 2016 14:26:05 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E0867303E3F3; Mon, 7 Mar 2016 20:25:57 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 7 Mar 2016 20:25:47 +0100 Message-Id: <1457378754-21649-36-git-send-email-armbru@redhat.com> In-Reply-To: <1457378754-21649-1-git-send-email-armbru@redhat.com> References: <1457378754-21649-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: claudio.fontana@huawei.com, cam@cs.ualberta.ca, mlureau@redhat.com, david.marchand@6wind.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 35/42] ivshmem: Inline check_shm_size() into its only caller X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 6a52a62..da80c8e 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -343,29 +343,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, @@ -480,7 +457,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) { @@ -489,8 +466,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; }