From patchwork Wed Jul 18 12:41:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 945702 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41VxcD6Mp3z9s21 for ; Wed, 18 Jul 2018 22:42:04 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41VxcC6X7NzF35L for ; Wed, 18 Jul 2018 22:42:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=thuth@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41Vxbw1pR3zF3Hb for ; Wed, 18 Jul 2018 22:41:48 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF8B7401EF32; Wed, 18 Jul 2018 12:41:45 +0000 (UTC) Received: from thh440s.str.redhat.com (dhcp-200-180.str.redhat.com [10.33.200.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81FC52026D69; Wed, 18 Jul 2018 12:41:45 +0000 (UTC) From: Thomas Huth To: slof@lists.ozlabs.org Date: Wed, 18 Jul 2018 14:41:41 +0200 Message-Id: <1531917704-21355-2-git-send-email-thuth@redhat.com> In-Reply-To: <1531917704-21355-1-git-send-email-thuth@redhat.com> References: <1531917704-21355-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 18 Jul 2018 12:41:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 18 Jul 2018 12:41:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Subject: [SLOF] [PATCH 1/4] romfs/tools: Remove superfluous union around the rom header struct X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" Accessing the struct with memset and memcpy can also be done without the union wrapper. Signed-off-by: Thomas Huth --- romfs/tools/create_crc.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/romfs/tools/create_crc.c b/romfs/tools/create_crc.c index 5a76b9c..d33dfe4 100644 --- a/romfs/tools/create_crc.c +++ b/romfs/tools/create_crc.c @@ -10,6 +10,7 @@ * IBM Corporation - initial implementation *****************************************************************************/ +#include #include #include #include @@ -71,21 +72,20 @@ createHeaderImage(int notime) char dastr[16] = { 0, }; unsigned long long da = 0; - union { - unsigned char pcArray[FLASHFS_HEADER_DATA_SIZE]; - struct stH stHeader; - } uHeader; + struct stH stHeader; + + assert(sizeof(stHeader) == FLASHFS_HEADER_DATA_SIZE); /* initialize Header */ - memset(uHeader.pcArray, 0x00, FLASHFS_HEADER_DATA_SIZE); + memset(&stHeader, 0x00, FLASHFS_HEADER_DATA_SIZE); /* read driver info */ if (NULL != (pcVersion = getenv("DRIVER_NAME"))) { - strncpy(uHeader.stHeader.version, pcVersion, 16); + strncpy(stHeader.version, pcVersion, 16); } else if (NULL != (pcVersion = getenv("USER"))) { - strncpy(uHeader.stHeader.version, pcVersion, 16); + strncpy(stHeader.version, pcVersion, 16); } else if (pcVersion == NULL) { - strncpy(uHeader.stHeader.version, "No known user!", 16); + strncpy(stHeader.version, "No known user!", 16); } if (!notime) { @@ -104,18 +104,18 @@ createHeaderImage(int notime) } da = cpu_to_be64(strtoll(dastr, NULL, 16)); } - memcpy(uHeader.stHeader.date, &da, 8); + memcpy(stHeader.date, &da, 8); /* write Magic value into data stream */ - strncpy(uHeader.stHeader.magic, FLASHFS_MAGIC, 8); + strncpy(stHeader.magic, FLASHFS_MAGIC, 8); /* write platform name into data stream */ - strcpy(uHeader.stHeader.platform_name, FLASHFS_PLATFORM_MAGIC); + strcpy(stHeader.platform_name, FLASHFS_PLATFORM_MAGIC); /* write platform revision into data stream */ - strcpy(uHeader.stHeader.platform_revision, FLASHFS_PLATFORM_REVISION); + strcpy(stHeader.platform_revision, FLASHFS_PLATFORM_REVISION); /* fill end of file info (8 bytes of FF) into data stream */ - uHeader.stHeader.ui64FileEnd = -1; + stHeader.ui64FileEnd = -1; /* read address of next file and address of header date, both are 64 bit values */ ui64RomAddr = 0; @@ -143,8 +143,7 @@ createHeaderImage(int notime) /* fill free space in Header with zeros */ memset(&pucFileStream[ui64DataAddr], 0, (ui64RomAddr - ui64DataAddr)); /* place data to header */ - memcpy(&pucFileStream[ui64DataAddr], uHeader.pcArray, - FLASHFS_HEADER_DATA_SIZE); + memcpy(&pucFileStream[ui64DataAddr], &stHeader, sizeof(stHeader)); /* insert header length into data stream */ *(uint64_t *) (pucFileStream + FLASHFS_HEADER_SIZE_ADDR) =