From patchwork Tue Jan 15 12:25:34 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: 212143 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 34D562C00A6 for ; Tue, 15 Jan 2013 23:25:41 +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 1Tv5aG-0006Av-1J; Tue, 15 Jan 2013 12:25:40 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tv5aC-0006AE-Vs for fwts-devel@lists.ubuntu.com; Tue, 15 Jan 2013 12:25:37 +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 1Tv5aC-0003nG-TQ for fwts-devel@lists.ubuntu.com; Tue, 15 Jan 2013 12:25:36 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/3] acpi: fadt: use new I/O port helpers to avoid segfaults Date: Tue, 15 Jan 2013 12:25:34 +0000 Message-Id: <1358252735-14227-3-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1358252735-14227-1-git-send-email-colin.king@canonical.com> References: <1358252735-14227-1-git-send-email-colin.king@canonical.com> 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 Use he new I/O port helper functions to avoid any segfaults. We also add some extra error checking on the ioperm() calls. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu Acked-by: Alex Hung --- src/acpi/fadt/fadt.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/acpi/fadt/fadt.c b/src/acpi/fadt/fadt.c index d7ee0aa..d18ca4e 100644 --- a/src/acpi/fadt/fadt.c +++ b/src/acpi/fadt/fadt.c @@ -54,7 +54,8 @@ static int fadt_init(fwts_framework *fw) static int fadt_test1(fwts_framework *fw) { - uint32_t port, width, value; + uint32_t port, width, val32; + int ret = FWTS_OK; /* Not having a FADT is not a failure */ if (fadt_size == 0) { @@ -94,19 +95,34 @@ static int fadt_test1(fwts_framework *fw) switch (width) { case 8: - ioperm(port, width/8, 1); - value = inb(fadt->pm1a_cnt_blk); - ioperm(port, width/8, 0); + if (ioperm(port, width/8, 1) < 0) + ret = FWTS_ERROR; + else { + uint8_t val8; + + ret = fwts_inb(port, &val8); + val32 = val8; + ioperm(port, width/8, 0); + } break; case 16: - ioperm(port, width/8, 1); - value = inw(fadt->pm1a_cnt_blk); - ioperm(port, width/8, 0); + if (ioperm(port, width/8, 1) < 0) + ret = FWTS_ERROR; + else { + uint16_t val16; + + ret = fwts_inw(port, &val16); + val32 = val16; + ioperm(port, width/8, 0); + } break; case 32: - ioperm(port, width/8, 1); - value = inl(fadt->pm1a_cnt_blk); - ioperm(port, width/8, 0); + if (ioperm(port, width/8, 1) < 0) + ret = FWTS_ERROR; + else { + ret = fwts_inl(port, &val32); + ioperm(port, width/8, 0); + } break; default: fwts_failed(fw, LOG_LEVEL_HIGH, "FADTPM1AInvalidWidth", @@ -116,7 +132,12 @@ static int fadt_test1(fwts_framework *fw) return FWTS_OK; } - if (value & 0x01) + if (ret != FWTS_OK) { + fwts_log_error(fw, "Cannot read FADT PM1A_CNT_BLK port 0x%" PRIx32 ".", port); + return FWTS_ERROR; + } + + if (val32 & 0x01) fwts_passed(fw, "SCI_EN bit in PM1a Control Register Block is enabled."); else { fwts_failed(fw, LOG_LEVEL_HIGH, "SCI_ENNotEnabled",