From patchwork Mon Feb 28 19:56:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Wessfeldt X-Patchwork-Id: 597211 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1SJvE6c000326 for ; Mon, 28 Feb 2011 19:57:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754535Ab1B1T5N (ORCPT ); Mon, 28 Feb 2011 14:57:13 -0500 Received: from mail-bw0-f46.google.com ([209.85.214.46]:50531 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754341Ab1B1T5M (ORCPT ); Mon, 28 Feb 2011 14:57:12 -0500 Received: by bwz15 with SMTP id 15so3993746bwz.19 for ; Mon, 28 Feb 2011 11:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=R37j8/LIDyujpioyc3+c8sxsN2o5VDiFtBzixIFL1r0=; b=WBCcLyoGZycmTpjqHjgAGUTQDJOHjyt8BrieK+Skv8ZR0eOFt3M3th0VS86xjWwacj Wv4Df1XNhCgbSLWCdaCogS2+DpStQL4OFnaBV1WMmb1HKES0O/WH78fMdPNtZIEgw50V jW9Wh6XKyZOziFgfl/euetShpAltPtvFY2nMU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=KZDhHLmi9W+lDLLlgKwVqWc8Vmr0PDkmkis17mKKv4NrYWLZvJd3+164tBM0gtj0Xh ETfiO8wGZJ2HmR/p7lXg11A+6hzyVQlVOnqGcGg76Al3d0pWOEjCqTiaiD70H1I9vKSD oLWh0fRLlLdiCDSQidQ8UmjS+XiKSSne9tbEU= Received: by 10.204.15.83 with SMTP id j19mr4099106bka.105.1298923031351; Mon, 28 Feb 2011 11:57:11 -0800 (PST) Received: from localhost (c-89-160-19-210.cust.bredband2.com [89.160.19.210]) by mx.google.com with ESMTPS id u23sm2808491bkw.9.2011.02.28.11.57.08 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Feb 2011 11:57:10 -0800 (PST) From: Johan Wessfeldt To: lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Wessfeldt Subject: [PATCH] acpi: Corrections of unchecked calls to request_region Date: Mon, 28 Feb 2011 20:56:48 +0100 Message-Id: <1298923008-16796-1-git-send-email-johan.wessfeldt@gmail.com> X-Mailer: git-send-email 1.7.2.3 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 28 Feb 2011 19:57:15 +0000 (UTC) diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index c90c76a..5c8c521 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -166,48 +166,77 @@ static u32 acpi_osi_handler(acpi_string interface, u32 supported) return supported; } -static void __init acpi_request_region (struct acpi_generic_address *addr, +static int __init acpi_request_region(struct acpi_generic_address *addr, unsigned int length, char *desc) { + struct resource *pRes; + if (!addr->address || !length) - return; + return -EIO; /* Resources are never freed */ - if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) - request_region(addr->address, length, desc); - else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) - request_mem_region(addr->address, length, desc); + if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { + pRes = request_region(addr->address, length, desc); + if (pRes == NULL) + return -EIO; + + } else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { + pRes = request_mem_region(addr->address, length, desc); + if (pRes == NULL) + return -EIO; + } + + return 0; } static int __init acpi_reserve_resources(void) { - acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, - "ACPI PM1a_EVT_BLK"); + if (!acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, + acpi_gbl_FADT.pm1_event_length, + "ACPI PM1a_EVT_BLK")) + return -EIO; - acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length, - "ACPI PM1b_EVT_BLK"); + if (!acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, + acpi_gbl_FADT.pm1_event_length, + "ACPI PM1b_EVT_BLK")) + return -EIO; - acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length, - "ACPI PM1a_CNT_BLK"); + if (!acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, + acpi_gbl_FADT.pm1_control_length, + "ACPI PM1a_CNT_BLK")) + return -EIO; - acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length, - "ACPI PM1b_CNT_BLK"); + if (!acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, + acpi_gbl_FADT.pm1_control_length, + "ACPI PM1b_CNT_BLK")) + return -EIO; - if (acpi_gbl_FADT.pm_timer_length == 4) - acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR"); + if (acpi_gbl_FADT.pm_timer_length == 4) { + if (!acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, + 4, "ACPI PM_TMR")) + return -EIO; + } - acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length, - "ACPI PM2_CNT_BLK"); + if (!acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, + acpi_gbl_FADT.pm2_control_length, + "ACPI PM2_CNT_BLK")) + return -EIO; /* Length of GPE blocks must be a non-negative multiple of 2 */ - if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) - acpi_request_region(&acpi_gbl_FADT.xgpe0_block, - acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); + if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) { + if (!acpi_request_region(&acpi_gbl_FADT.xgpe0_block, + acpi_gbl_FADT.gpe0_block_length, + "ACPI GPE0_BLK")) + return -EIO; + } - if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) - acpi_request_region(&acpi_gbl_FADT.xgpe1_block, - acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); + if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) { + if (!acpi_request_region(&acpi_gbl_FADT.xgpe1_block, + acpi_gbl_FADT.gpe1_block_length, + "ACPI GPE1_BLK")) + return -EIO; + } return 0; }