From patchwork Wed Jun 11 14:50:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 358724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8FAE6140085 for ; Thu, 12 Jun 2014 00:54:05 +1000 (EST) Received: from localhost ([::1]:46978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujud-0001Xe-IG for incoming@patchwork.ozlabs.org; Wed, 11 Jun 2014 10:54:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujs3-0005i8-Ey for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wujrr-00086Y-JM for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38078) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujrr-00086N-Ad for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:11 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5BEp77Y010549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Jun 2014 10:51:07 -0400 Received: from localhost (ovpn-113-65.phx2.redhat.com [10.3.113.65]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5BEp7Yb027525; Wed, 11 Jun 2014 10:51:07 -0400 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Wed, 11 Jun 2014 10:50:47 -0400 Message-Id: <1402498262-20521-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1402498262-20521-1-git-send-email-lcapitulino@redhat.com> References: <1402498262-20521-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 02/17] dump: simplify write_start_flat_header() 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Laszlo Ersek Currently, the function - defines and populates an auto variable of type MakedumpfileHeader - allocates and zeroes a buffer of size MAX_SIZE_MDF_HEADER (4096) - copies the former into the latter (covering an initial portion of the latter) Fill in the MakedumpfileHeader structure in its final place (the alignment is OK because the structure lives at the address returned by g_malloc0()). Approximately-suggested-by: Luiz Capitulino Signed-off-by: Laszlo Ersek Reviewed-by: Paolo Bonzini Signed-off-by: Luiz Capitulino --- dump.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dump.c b/dump.c index ac4505e..6dec8d2 100644 --- a/dump.c +++ b/dump.c @@ -711,27 +711,25 @@ static int create_vmcore(DumpState *s) static int write_start_flat_header(int fd) { - uint8_t *buf; - MakedumpfileHeader mh; + MakedumpfileHeader *mh; int ret = 0; - memset(&mh, 0, sizeof(mh)); - memcpy(mh.signature, MAKEDUMPFILE_SIGNATURE, - MIN(sizeof mh.signature, sizeof MAKEDUMPFILE_SIGNATURE)); + QEMU_BUILD_BUG_ON(sizeof *mh > MAX_SIZE_MDF_HEADER); + mh = g_malloc0(MAX_SIZE_MDF_HEADER); - mh.type = cpu_to_be64(TYPE_FLAT_HEADER); - mh.version = cpu_to_be64(VERSION_FLAT_HEADER); + memcpy(mh->signature, MAKEDUMPFILE_SIGNATURE, + MIN(sizeof mh->signature, sizeof MAKEDUMPFILE_SIGNATURE)); - buf = g_malloc0(MAX_SIZE_MDF_HEADER); - memcpy(buf, &mh, sizeof(mh)); + mh->type = cpu_to_be64(TYPE_FLAT_HEADER); + mh->version = cpu_to_be64(VERSION_FLAT_HEADER); size_t written_size; - written_size = qemu_write_full(fd, buf, MAX_SIZE_MDF_HEADER); + written_size = qemu_write_full(fd, mh, MAX_SIZE_MDF_HEADER); if (written_size != MAX_SIZE_MDF_HEADER) { ret = -1; } - g_free(buf); + g_free(mh); return ret; }