From patchwork Wed Jun 26 16:30:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2787221 Return-Path: X-Original-To: patchwork-linux-acpi@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 126E19F968 for ; Wed, 26 Jun 2013 16:35:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF41F205B9 for ; Wed, 26 Jun 2013 16:35:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 700E0205C4 for ; Wed, 26 Jun 2013 16:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752275Ab3FZQeE (ORCPT ); Wed, 26 Jun 2013 12:34:04 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:44209 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752707Ab3FZQeB (ORCPT ); Wed, 26 Jun 2013 12:34:01 -0400 Received: by mail-pa0-f51.google.com with SMTP id lf11so14265910pab.24 for ; Wed, 26 Jun 2013 09:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=MIIn4gWkkyhhqX5qZXXIDb341ERXifz7nS9LWDt6zOU=; b=Iv8x+KiZkSt2pg/rMnjWH20ZkvbJCPj4WKejCnHZ7ih+jHA6c6e07mdLMmStDMQ2HK ovrEksBvQef3MdL6xK+lQsDCB4HtwQIbctgjoIrwzVBfPdbf16qJyICgUoJzbPn5FZG8 NAs6p1FBWlJG5VA8dTTHoduNIHpLgQPipD/NkRrhgc4tYFru+KYJKzKDqdLu0nW/1OBp Hrgp8lY6Bbmp4424UxIf3LSkHtQVRLfrbRcHrpaaPOqcwcYa1PmZleRyndtGnEJtQbtd W/U3kjL8pButLcbuPvul+n8EjSqRGapyDhW4+zIekDXAsAQBC4nO85Bz5TEek3LMmkXD I92A== X-Received: by 10.66.139.227 with SMTP id rb3mr1568745pab.121.1372264441105; Wed, 26 Jun 2013 09:34:01 -0700 (PDT) Received: from localhost.localdomain ([114.250.101.234]) by mx.google.com with ESMTPSA id ib9sm28981911pbc.43.2013.06.26.09.33.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Jun 2013 09:34:00 -0700 (PDT) From: Jiang Liu To: "Rafael J . Wysocki" Cc: liuj97@gmail.com, Jiang Liu , Yijing Wang , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Len Brown Subject: [PATCH v2 6/9] ACPI: change acpi_[bay|dock]_match() in scan.c as global functions Date: Thu, 27 Jun 2013 00:30:58 +0800 Message-Id: <1372264261-17442-7-git-send-email-liuj97@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1372264261-17442-1-git-send-email-liuj97@gmail.com> References: <1372264261-17442-1-git-send-email-liuj97@gmail.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 From: Jiang Liu Function acpi_[bay|dock]_match() in scan.c could be shared with dock.c to reduce duplicated code, so refine and change them as global functions. Also add a new function acpi_ata_match() to check whether an ACPI object device is an ATA device. Signed-off-by: Jiang Liu Cc: Jiang Liu Cc: Len Brown Cc: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/acpi/scan.c | 82 ++++++++++++++++++++++--------------------------- include/acpi/acpi_bus.h | 3 ++ 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index dfe76f1..3ddba74 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1532,46 +1532,45 @@ static void acpi_device_get_busid(struct acpi_device *device) } /* + * acpi_ata_match - see if an acpi object is an ATA device + * + * If an acpi object has one of the ACPI ATA methods defined, + * then we can safely call it an ATA device. + */ +bool acpi_ata_match(acpi_handle handle) +{ + return acpi_has_method(handle, "_GTF") || + acpi_has_method(handle, "_GTM") || + acpi_has_method(handle, "_STM") || + acpi_has_method(handle, "_SDD"); +} + +/* * acpi_bay_match - see if an acpi object is an ejectable driver bay * * If an acpi object is ejectable and has one of the ACPI ATA methods defined, * then we can safely call it an ejectable drive bay */ -static int acpi_bay_match(acpi_handle handle) +bool acpi_bay_match(acpi_handle handle) { - acpi_status status; - acpi_handle tmp; acpi_handle phandle; - status = acpi_get_handle(handle, "_EJ0", &tmp); - if (ACPI_FAILURE(status)) - return -ENODEV; - - if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) || - (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) || - (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) || - (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp)))) - return 0; - - if (acpi_get_parent(handle, &phandle)) - return -ENODEV; - - if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) || - (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) || - (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) || - (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp)))) - return 0; + if (!acpi_has_method(handle, "_EJ0")) + return false; + if (acpi_ata_match(handle)) + return true; + if (ACPI_FAILURE(acpi_get_parent(handle, &phandle))) + return false; - return -ENODEV; + return acpi_ata_match(phandle); } /* * acpi_dock_match - see if an acpi object has a _DCK method */ -static int acpi_dock_match(acpi_handle handle) +bool acpi_dock_match(acpi_handle handle) { - acpi_handle tmp; - return acpi_get_handle(handle, "_DCK", &tmp); + return acpi_has_method(handle, "_DCK"); } const char *acpi_device_hid(struct acpi_device *device) @@ -1609,34 +1608,27 @@ static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id) * lacks the SMBUS01 HID and the methods do not have the necessary "_" * prefix. Work around this. */ -static int acpi_ibm_smbus_match(acpi_handle handle) +static bool acpi_ibm_smbus_match(acpi_handle handle) { acpi_handle h_dummy; - struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL}; - int result; + char node_name[ACPI_PATH_SEGMENT_LENGTH]; + struct acpi_buffer path = { sizeof(node_name), node_name }; if (!dmi_name_in_vendors("IBM")) - return -ENODEV; + return false; /* Look for SMBS object */ - result = acpi_get_name(handle, ACPI_SINGLE_NAME, &path); - if (result) - return result; - - if (strcmp("SMBS", path.pointer)) { - result = -ENODEV; - goto out; - } + if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) || + strcmp("SMBS", path.pointer)) + return false; /* Does it have the necessary (but misnamed) methods? */ - result = -ENODEV; if (ACPI_SUCCESS(acpi_get_handle(handle, "SBI", &h_dummy)) && ACPI_SUCCESS(acpi_get_handle(handle, "SBR", &h_dummy)) && ACPI_SUCCESS(acpi_get_handle(handle, "SBW", &h_dummy))) - result = 0; -out: - kfree(path.pointer); - return result; + return true; + + return false; } static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, @@ -1684,11 +1676,11 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, */ if (acpi_is_video_device(handle)) acpi_add_id(pnp, ACPI_VIDEO_HID); - else if (ACPI_SUCCESS(acpi_bay_match(handle))) + else if (acpi_bay_match(handle)) acpi_add_id(pnp, ACPI_BAY_HID); - else if (ACPI_SUCCESS(acpi_dock_match(handle))) + else if (acpi_dock_match(handle)) acpi_add_id(pnp, ACPI_DOCK_HID); - else if (!acpi_ibm_smbus_match(handle)) + else if (acpi_ibm_smbus_match(handle)) acpi_add_id(pnp, ACPI_SMBUS_IBM_HID); else if (list_empty(&pnp->ids) && handle == ACPI_ROOT_OBJECT) { acpi_add_id(pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 3db3b97..a4e4427 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -60,6 +60,9 @@ acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld acpi_status acpi_evaluate_ej0(acpi_handle handle); acpi_status acpi_evaluate_lck(acpi_handle handle, int lock); bool acpi_has_method(acpi_handle handle, char *name); +bool acpi_ata_match(acpi_handle handle); +bool acpi_bay_match(acpi_handle handle); +bool acpi_dock_match(acpi_handle handle); #ifdef CONFIG_ACPI