From patchwork Tue Mar 10 22:08:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 448728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id F288814008F for ; Wed, 11 Mar 2015 08:46:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752658AbbCJVqZ (ORCPT ); Tue, 10 Mar 2015 17:46:25 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:63486 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752260AbbCJVqY (ORCPT ); Tue, 10 Mar 2015 17:46:24 -0400 Received: from cmk94.neoplus.adsl.tpnet.pl (83.31.138.94) (HELO vostro.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer v0.80) id cce1b2119b5aa7b9; Tue, 10 Mar 2015 22:46:22 +0100 From: "Rafael J. Wysocki" To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, Linux Kernel Mailing List , ACPI Devel Maling List , Mika Westerberg Subject: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Date: Tue, 10 Mar 2015 23:08:57 +0100 Message-ID: <1829371.gDPkhnsp25@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/3.19.0+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <4032246.STUT1iRmIk@vostro.rjw.lan> References: <4032246.STUT1iRmIk@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Rafael J. Wysocki If dev is NULL in __gpiod_get_index() and both ACPI and OF are enabled, it will be checked twice before the code decides to give up with DT/ACPI lookup, so avoid that. Also use the observation that ACPI_COMPANION() is much more efficient than ACPI_HANDLE(), because the latter uses the former and carries out a check and a pointer dereference on top of it, so replace the ACPI_HANDLE() check with an ACPI_COMPANION() one which does not require the additional IS_ENABLED(CONFIG_ACPI) check too. Signed-off-by: Rafael J. Wysocki Reviewed-by: Hanjun Guo Acked-by: Mika Westerberg --- drivers/gpio/gpiolib.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-pm/drivers/gpio/gpiolib.c =================================================================== --- linux-pm.orig/drivers/gpio/gpiolib.c +++ linux-pm/drivers/gpio/gpiolib.c @@ -1865,13 +1865,15 @@ struct gpio_desc *__must_check __gpiod_g dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); - /* Using device tree? */ - if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) { - dev_dbg(dev, "using device tree for GPIO lookup\n"); - desc = of_find_gpio(dev, con_id, idx, &lookupflags); - } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) { - dev_dbg(dev, "using ACPI for GPIO lookup\n"); - desc = acpi_find_gpio(dev, con_id, idx, &lookupflags); + if (dev) { + /* Using device tree? */ + if (IS_ENABLED(CONFIG_OF) && dev->of_node) { + dev_dbg(dev, "using device tree for GPIO lookup\n"); + desc = of_find_gpio(dev, con_id, idx, &lookupflags); + } else if (ACPI_COMPANION(dev)) { + dev_dbg(dev, "using ACPI for GPIO lookup\n"); + desc = acpi_find_gpio(dev, con_id, idx, &lookupflags); + } } /*