From patchwork Thu Aug 4 22:26:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 108582 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 71F49B6F72 for ; Fri, 5 Aug 2011 08:26:54 +1000 (EST) Received: from localhost ([::1]:35240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qp6NO-0007DY-KJ for incoming@patchwork.ozlabs.org; Thu, 04 Aug 2011 18:26:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qp6NH-0007DI-Q0 for qemu-devel@nongnu.org; Thu, 04 Aug 2011 18:26:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qp6NG-000893-BC for qemu-devel@nongnu.org; Thu, 04 Aug 2011 18:26:43 -0400 Received: from mail-fx0-f45.google.com ([209.85.161.45]:34966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qp6NG-00088q-5T for qemu-devel@nongnu.org; Thu, 04 Aug 2011 18:26:42 -0400 Received: by fxbb27 with SMTP id b27so651153fxb.4 for ; Thu, 04 Aug 2011 15:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:content-transfer-encoding:user-agent; bh=c4H2vRkgsSFr/1ihmEyX1zerk3smgtrQWXEt3s3mrLk=; b=rkC6ugx7VAIGvc8Sxl9fdwbiP1nR8xS5m/VMI7gY4kV6tsSTtmShLIyxtbQ6+tcr43 f1G4SOlwWDC5jmjvaPhzxjDiM8pHqThDbswJ7vbPKjryStnqE3cu+gvrhWmwsyiCs8CZ 4OgZhmAZgbyH5ynF02QYg0kDn1rwnnm59fKys= Received: by 10.223.54.20 with SMTP id o20mr1887060fag.27.1312496800941; Thu, 04 Aug 2011 15:26:40 -0700 (PDT) Received: from localhost (h59ec324b.selukar.dyn.perspektivbredband.net [89.236.50.75]) by mx.google.com with ESMTPS id y15sm1537553fah.11.2011.08.04.15.26.39 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 04 Aug 2011 15:26:40 -0700 (PDT) Date: Fri, 5 Aug 2011 00:26:38 +0200 From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Message-ID: <20110804222638.GB2601@zapo> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.45 Subject: [Qemu-devel] [PATCH] fw_cfg: Simplify error paths and avoid warnings 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 master branch doesnt build due to 3d3b8303c6f83b9b245bc774af530a6403cc4ce6 hw/fw_cfg.c: In function ‘probe_splashfile’: hw/fw_cfg.c:66:9: error: variable ‘fop_ret’ set but not used [-Werror=unused-but-set-variable] hw/fw_cfg.c: In function ‘fw_cfg_bootsplash’: hw/fw_cfg.c:130:9: error: variable ‘fop_ret’ set but not used [-Werror=unused-but-set-variable] This is a basically untested fix, compile tested only. Cheers --- commit fb4515b04705414ab9ea9d5deb4728b41525761e Author: Edgar E. Iglesias Date: Thu Aug 4 01:17:16 2011 +0200 fw_cfg: Simplify error paths and avoid warnings Signed-off-by: Edgar E. Iglesias diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c index a29db90..8593c25 100644 --- a/hw/fw_cfg.c +++ b/hw/fw_cfg.c @@ -80,13 +80,15 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep) file_size = ftell(fp); if (file_size < 2) { error_report("file size is less than 2 bytes '%s'.", filename); - fclose(fp); - fp = NULL; - return fp; + goto fail; } /* check magic ID */ fseek(fp, 0L, SEEK_SET); fop_ret = fread(buf, 1, 2, fp); + if (fop_ret != 2) { + goto fail; + } + filehead_value = (buf[0] + (buf[1] << 8)) & 0xffff; if (filehead_value == 0xd8ff) { file_type = JPG_FILE; @@ -98,9 +100,7 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep) if (file_type < 0) { error_report("'%s' not jpg/bmp file,head:0x%x.", filename, filehead_value); - fclose(fp); - fp = NULL; - return fp; + goto fail; } /* check BMP bpp */ if (file_type == BMP_FILE) { @@ -109,15 +109,17 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep) bmp_bpp = (buf[0] + (buf[1] << 8)) & 0xffff; if (bmp_bpp != 24) { error_report("only 24bpp bmp file is supported."); - fclose(fp); - fp = NULL; - return fp; + goto fail; } } /* return values */ *file_sizep = file_size; *file_typep = file_type; return fp; + +fail: + fclose(fp); + return NULL; } static void fw_cfg_bootsplash(FWCfgState *s) @@ -169,8 +171,8 @@ static void fw_cfg_bootsplash(FWCfgState *s) } /* probing the file */ fp = probe_splashfile(filename, &file_size, &file_type); + qemu_free(filename); if (fp == NULL) { - qemu_free(filename); return; } /* loading file data */ @@ -182,6 +184,10 @@ static void fw_cfg_bootsplash(FWCfgState *s) fseek(fp, 0L, SEEK_SET); fop_ret = fread(boot_splash_filedata, 1, file_size, fp); fclose(fp); + if (fop_ret != file_size) { + return; + } + /* insert data */ if (file_type == JPG_FILE) { fw_cfg_add_file(s, "bootsplash.jpg", @@ -190,7 +196,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) fw_cfg_add_file(s, "bootsplash.bmp", boot_splash_filedata, boot_splash_filedata_size); } - qemu_free(filename); } }