From patchwork Wed Jan 16 00:53:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 212358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id EB4332C009B for ; Wed, 16 Jan 2013 11:53:54 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TvHGK-0008Ef-68; Wed, 16 Jan 2013 00:53:52 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TvHGJ-0008Ea-03 for fwts-devel@lists.ubuntu.com; Wed, 16 Jan 2013 00:53:51 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TvHGI-00089W-U1 for fwts-devel@lists.ubuntu.com; Wed, 16 Jan 2013 00:53:50 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] hpet: hpetcheck: fix a bug found by smatch Date: Wed, 16 Jan 2013 00:53:50 +0000 Message-Id: <1358297630-7279-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King smatch found a bug that needs fixing: "hpet_check.c:88 hpet_parse_device_hpet() error: we previously assumed 'tmp_item' could be null (see line 81)" Re-work the HPET parsing so that we sanely handle tmp_item. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Alex Hung --- src/hpet/hpet_check/hpet_check.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/hpet/hpet_check/hpet_check.c b/src/hpet/hpet_check/hpet_check.c index 7709f88..8fe124a 100644 --- a/src/hpet/hpet_check/hpet_check.c +++ b/src/hpet/hpet_check/hpet_check.c @@ -70,29 +70,25 @@ static void hpet_parse_device_hpet(fwts_framework *fw, const char *table, fwts_list_link *item) { for (;item != NULL; item = item->next) { - char *str = fwts_text_list_text(item); + const char *str = fwts_text_list_text(item); + if ((strstr(str, "Name") != NULL) && - (strstr(str, "ResourceTemplate") != NULL)) { + (strstr(str, "ResourceTemplate") != NULL)) { fwts_list_link *tmp_item = item->next; for (; tmp_item != NULL; tmp_item = tmp_item->next) { - if (strstr(fwts_text_list_text(tmp_item), - "Memory32Fixed") != NULL) { - tmp_item = tmp_item->next; - if (tmp_item != NULL) { - hpet_parse_check_base(fw, table, tmp_item); + const char *str = fwts_text_list_text(tmp_item); + + if (strstr(str, "Memory32Fixed") != NULL) { + /* Next line contains base address */ + if (tmp_item->next != NULL) { + hpet_parse_check_base(fw, table, tmp_item->next); return; } - } - if (strstr(fwts_text_list_text(tmp_item), - "DWordMemory") != NULL) { - tmp_item = tmp_item->next; - if (tmp_item != NULL) { - tmp_item = tmp_item->next; - if (tmp_item != NULL) { - /* HPET section is found, get base */ - hpet_parse_check_base(fw, table, tmp_item); - return; - } + } else if (strstr(str, "DWordMemory") != NULL) { + if (tmp_item->next != NULL && /* Granularity */ + tmp_item->next->next != NULL) { /* Base address */ + hpet_parse_check_base(fw, table, tmp_item->next->next); + return; } } }