From patchwork Tue Jan 15 12:25:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2/3] acpi: fadt: use new I/O port helpers to avoid segfaults From: Colin King X-Patchwork-Id: 212143 Message-Id: <1358252735-14227-3-git-send-email-colin.king@canonical.com> To: fwts-devel@lists.ubuntu.com Date: Tue, 15 Jan 2013 12:25:34 +0000 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",