From patchwork Tue Oct 8 18:15:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 3004691 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BDAFC9F1E1 for ; Tue, 8 Oct 2013 18:19:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E6C9201E4 for ; Tue, 8 Oct 2013 18:19:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6FB3A201A4 for ; Tue, 8 Oct 2013 18:19:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E877E6453 for ; Tue, 8 Oct 2013 11:19:21 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id BAB64E60E1 for ; Tue, 8 Oct 2013 11:18:27 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 08 Oct 2013 11:18:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="4.90,1057,1371106800"; d="scan'208"; a="389992218" Received: from junemccl-mobl.ger.corp.intel.com (HELO localhost) ([10.252.120.196]) by orsmga001.jf.intel.com with ESMTP; 08 Oct 2013 11:18:25 -0700 From: Jani Nikula To: intel-gfx@lists.freedesktop.org Date: Tue, 8 Oct 2013 21:15:26 +0300 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Cc: jani.nikula@intel.com Subject: [Intel-gfx] [IGT PATCH 1/4] intel_bios_reader: add size temp variable as a shorthand for finfo.st_size X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 Signed-off-by: Jani Nikula --- tools/intel_bios_reader.c | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c index 493fb63..d30026e 100644 --- a/tools/intel_bios_reader.c +++ b/tools/intel_bios_reader.c @@ -835,6 +835,7 @@ int main(int argc, char **argv) int vbt_off, bdb_off, i; const char *filename = "bios"; struct stat finfo; + int size; struct bdb_block *block; char signature[17]; char *devid_string; @@ -860,12 +861,13 @@ int main(int argc, char **argv) strerror(errno)); return 1; } + size = finfo.st_size; - if (finfo.st_size == 0) { + if (size == 0) { int len = 0, ret; - finfo.st_size = 8192; - VBIOS = malloc (finfo.st_size); - while ((ret = read(fd, VBIOS + len, finfo.st_size - len))) { + size = 8192; + VBIOS = malloc (size); + while ((ret = read(fd, VBIOS + len, size - len))) { if (ret < 0) { printf("failed to read \"%s\": %s\n", filename, strerror(errno)); @@ -873,13 +875,13 @@ int main(int argc, char **argv) } len += ret; - if (len == finfo.st_size) { - finfo.st_size *= 2; - VBIOS = realloc(VBIOS, finfo.st_size); + if (len == size) { + size *= 2; + VBIOS = realloc(VBIOS, size); } } } else { - VBIOS = mmap(NULL, finfo.st_size, PROT_READ, MAP_SHARED, fd, 0); + VBIOS = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (VBIOS == MAP_FAILED) { printf("failed to map \"%s\": %s\n", filename, strerror(errno)); return 1; @@ -887,7 +889,7 @@ int main(int argc, char **argv) } /* Scour memory looking for the VBT signature */ - for (i = 0; i + 4 < finfo.st_size; i++) { + for (i = 0; i + 4 < size; i++) { if (!memcmp(VBIOS + i, "$VBT", 4)) { vbt_off = i; vbt = (struct vbt_header *)(VBIOS + i); @@ -903,7 +905,7 @@ int main(int argc, char **argv) printf("VBT vers: %d.%d\n", vbt->version / 100, vbt->version % 100); bdb_off = vbt_off + vbt->bdb_offset; - if (bdb_off >= finfo.st_size - sizeof(struct bdb_header)) { + if (bdb_off >= size - sizeof(struct bdb_header)) { printf("Invalid VBT found, BDB points beyond end of data block\n"); return 1; } @@ -916,7 +918,7 @@ int main(int argc, char **argv) printf("Available sections: "); for (i = 0; i < 256; i++) { - block = find_section(i, finfo.st_size); + block = find_section(i, size); if (!block) continue; printf("%d ", i); @@ -929,19 +931,19 @@ int main(int argc, char **argv) if (devid == -1) printf("Warning: could not find PCI device ID!\n"); - dump_general_features(finfo.st_size); - dump_general_definitions(finfo.st_size); - dump_child_devices(finfo.st_size); - dump_lvds_options(finfo.st_size); - dump_lvds_data(finfo.st_size); - dump_lvds_ptr_data(finfo.st_size); - dump_backlight_info(finfo.st_size); + dump_general_features(size); + dump_general_definitions(size); + dump_child_devices(size); + dump_lvds_options(size); + dump_lvds_data(size); + dump_lvds_ptr_data(size); + dump_backlight_info(size); - dump_sdvo_lvds_options(finfo.st_size); - dump_sdvo_panel_dtds(finfo.st_size); + dump_sdvo_lvds_options(size); + dump_sdvo_panel_dtds(size); - dump_driver_feature(finfo.st_size); - dump_edp(finfo.st_size); + dump_driver_feature(size); + dump_edp(size); return 0; }