From patchwork Mon Oct 26 10:20:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 7486801 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 14A239F2F7 for ; Mon, 26 Oct 2015 10:20:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 447DA20695 for ; Mon, 26 Oct 2015 10:20:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 346D920692 for ; Mon, 26 Oct 2015 10:20:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753624AbbJZKUf (ORCPT ); Mon, 26 Oct 2015 06:20:35 -0400 Received: from mga14.intel.com ([192.55.52.115]:53982 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753496AbbJZKUe (ORCPT ); Mon, 26 Oct 2015 06:20:34 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 26 Oct 2015 03:20:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,201,1444719600"; d="scan'208";a="835554779" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.200]) by fmsmga002.fm.intel.com with SMTP; 26 Oct 2015 03:20:32 -0700 Received: by lahna (sSMTP sendmail emulation); Mon, 26 Oct 2015 12:20:31 +0200 Date: Mon, 26 Oct 2015 12:20:31 +0200 From: Mika Westerberg To: Daniel =?iso-8859-1?Q?Gl=F6ckner?= Cc: linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org Subject: Re: acpi_find_gpio with absent GPIOs Message-ID: <20151026102031.GG1526@lahna.fi.intel.com> References: <562A4AB6.1010805@emlix.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <562A4AB6.1010805@emlix.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 On Fri, Oct 23, 2015 at 04:56:54PM +0200, Daniel Glöckner wrote: > Hi, > > I'm currently trying to use rfkill-gpio with a device that has just a > single GPIO assigned by ACPI. rfkill-gpio calls acpi_dev_add_driver_gpios > to assign names to the ACPI GPIOs and then uses devm_gpiod_get_optional > to request both of them. The problem is that on the second call to > devm_gpiod_get_optional acpi_find_gpio falls back to using the GPIO index > 0 (from gpiod_get) in _CRS, which leads to the same GPIO being returned > as in the first call. Probing the driver then fails with -EBUSY. > > In my opinion it is a bad idea to fall back to indexing the _CRS if the > con_id was found in the _DSD or the GPIOs added by > acpi_dev_add_driver_gpios, but I don't know if there are drivers relying > on this behavior. I agree it is bad idea and I think this is actually a bug in the implementation rather than wanted behavior. No drivers should rely on that anyway. > Luckily acpi_get_gpiod_by_index returns -ENODATA if the name can't be > found and -ENOENT if the GPIO is absent, so we can distinguish the two > cases. -EPROBE_DEFER also should not make acpi_find_gpio try to use > another GPIO from the _CRS. > > There is also the possibility that the GPIO index exceeds the size of > the package found in _DSD or added with acpi_dev_add_driver_gpios. > The former will return -EPROTO, the latter will forward the error > from acpi_dev_get_property_reference (usually -ENODATA). of_find_gpio > returns -ENOENT in this case. > > So, what of this should be fixed? I think both should be fixed. For the first maybe something like below? --- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5db3445552b1..441be96e18e7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1765,6 +1765,11 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, /* Then from plain _CRS GPIOs */ if (IS_ERR(desc)) { + /* Only fallback if the device has no properties at all */ + if (PTR_ERR(desc) == -ENODATA && + (adev->data.properties || adev->driver_gpios)) + return ERR_PTR(-ENOENT); + desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); if (IS_ERR(desc)) return desc;