From patchwork Sat Jan 10 17:53:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 427385 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A1E3D14015A for ; Sun, 11 Jan 2015 04:54:09 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 670354B60B; Sat, 10 Jan 2015 18:54:06 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N+R1dtd177LQ; Sat, 10 Jan 2015 18:54:06 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A3CC04B605; Sat, 10 Jan 2015 18:54:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CCC214B605 for ; Sat, 10 Jan 2015 18:54:00 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 03wrXTWUYbHz for ; Sat, 10 Jan 2015 18:54:00 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ig0-f202.google.com (mail-ig0-f202.google.com [209.85.213.202]) by theia.denx.de (Postfix) with ESMTPS id 700D24B601 for ; Sat, 10 Jan 2015 18:53:56 +0100 (CET) Received: by mail-ig0-f202.google.com with SMTP id hn18so808173igb.1 for ; Sat, 10 Jan 2015 09:53:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/nYFmmlth21AChWEzUuzNzzumQcb7n/QnnE88chvJTQ=; b=QupkSU4WZkrVy6cipGhGS24pcOYGE23ZZWSR7MTNW0tczsBTexakH7qtFOFAzVdPOe L7BuLWisaBXJAiZ6RNqanjfHZ+ddlERdjf2Cl4s0qOX0SdjsbEAH4HBjGmIJCrsfeb+N vjku4B6JkARoU9s1IIAyd7GLWgDEbu+m74nG0W8OLywz3mjenhMMvbLynv0ly/9DHy92 ba0ej+I4ejR6S1VuQGNJf2Bh6baFwFyoxx2YLl1PO4o2acaHozwL8xmSZkNJ7Vjzctut /mvzQycfEdCA90kpINiNVC2cOBkH/VxNaR4wW7XQc3RKTWUJLmxMp5OMEB31cSSaWe0r y8Eg== X-Gm-Message-State: ALoCoQl42bkZKUIFpZ+qlFqIjCwV42I7WUrMgA29My2mfvB1WoiqXaun6wl2xO+EoGlRGb/9RA5D X-Received: by 10.42.198.77 with SMTP id en13mr17149173icb.21.1420912435319; Sat, 10 Jan 2015 09:53:55 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id t7si462032yho.3.2015.01.10.09.53.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Jan 2015 09:53:55 -0800 (PST) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id ROBP1zRM.1; Sat, 10 Jan 2015 09:53:55 -0800 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 30D3922089B; Sat, 10 Jan 2015 10:53:54 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Sat, 10 Jan 2015 10:53:51 -0700 Message-Id: <1420912431-1920-1-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c Cc: Angelo Dureghello , Jeroen Hofstee , Tom Rini , Stefan Roese Subject: [U-Boot] [PATCH] kwbimage: Correct a long-standing warning X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de tools/kwbimage.c:803:8: warning: 'headersz' may be used uninitialized in this function [-Wmaybe-uninitialized] This problem was discussed twice previously, but neither solution has been applied to mainline. This is another attempt at a possible solution before the release goes out and we are stuck with it. https://patchwork.ozlabs.org/patch/412968/ https://patchwork.ozlabs.org/patch/417410/ Signed-off-by: Simon Glass --- tools/kwbimage.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c50f2e2..937b208 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -302,6 +302,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, * Calculate the size of the header and the size of the * payload */ + *imagesz = 0; headersz = sizeof(struct main_hdr_v0); if (image_count_options(IMAGE_CFG_DATA) > 0) { @@ -441,6 +442,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, * Calculate the size of the header and the size of the * payload */ + *imagesz = 0; headersz = image_headersz_v1(params, &hasext); if (headersz == 0) return NULL; @@ -737,7 +739,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (!fcfg) { fprintf(stderr, "Could not open input file %s\n", params->imagename); - exit(EXIT_FAILURE); + goto err; } image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX * @@ -745,7 +747,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (!image_cfg) { fprintf(stderr, "Cannot allocate memory\n"); fclose(fcfg); - exit(EXIT_FAILURE); + goto err; } memset(image_cfg, 0, @@ -756,7 +758,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, fclose(fcfg); if (ret) { free(image_cfg); - exit(EXIT_FAILURE); + goto err; } version = image_get_version(); @@ -777,13 +779,13 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, default: fprintf(stderr, "Unsupported version %d\n", version); free(image_cfg); - exit(EXIT_FAILURE); + goto err; } if (!image) { fprintf(stderr, "Could not create image\n"); free(image_cfg); - exit(EXIT_FAILURE); + goto err; } free(image_cfg); @@ -794,7 +796,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (size != sizeof(uint32_t)) { fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n", params->cmdname, size, params->imagefile); - exit(EXIT_FAILURE); + goto err; } sbuf->st_size += sizeof(uint32_t); @@ -803,6 +805,13 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, memcpy(ptr, image, headersz); free(image); + +err: + /* + * TODO: Adjust the struct image_type_params set_header() method to + * return an error instead of calling exit() here. + */ + exit(EXIT_FAILURE); } static void kwbimage_print_header(const void *ptr)