Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10908089ybi; Thu, 25 Jul 2019 06:55:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwN8kjYzr9ikKvKTXqb5QFuLEw1nNQv8PnfxoqQOOcxnoXIlDYYj0txzzDqveeuZYOcDsMO X-Received: by 2002:a17:90a:ac13:: with SMTP id o19mr93209945pjq.143.1564062929183; Thu, 25 Jul 2019 06:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564062929; cv=none; d=google.com; s=arc-20160816; b=ROIjLhnrhE7o3Dr6HsuLJLu7nIT8biz7IJfe2fOIn4LQ11vcnJG2+caBCpSAaaBo0T 3A3OUA1pCnl7pJ+QIg2pAlCSwATbl2k9FDpzxWVH9nEZ/o386ejr5WodW56ZnD+ibtY7 w4ypFwLrxk/ahkETenqaLDxD6BQJPYIwAuaaKqzAP0IgM2Kt+qlUEWnbjtHoKXmp5rip P87o/nwJWbhe04l/PJXv9ekovCN/QpcpS4ymX3F1BqCmtOrJ5/hKQavGWQz+gNTIgwLq PMy4nPxCdcdz5laMkVZVkt3c2JyM13vHYpVDnlrTp3ew9MqiKX1vvg/9N5/pCDWr/sE9 /PxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=csWNUlHJ/ntnfRvH5s/ZUoimVsPonbJ487sYx30sDC4=; b=Gn3cpTo5N4FgjGPqgUG18C+gtFrSe04s7X4Xw5ol2cCUIFBZPCzX/IQBQoqH0Cw2Wc WY9M1sPH3mMnrqiH75imVDhr6Bd96xVLAPlNgViKQFrXG0UaWgL484xq3dq6UiMnZ0eS P56gUky0O0O1SfcdBTOh5yqOxEjq0hvAbMqNwJexVa5bk4RqL6aMe0Nc6OuZI7l76nPa 02DAocEOFMP1ZNUW3KzG5fQgnPV0TuOBenhcPm+M+yP2nLzg0tt16Izm+I14rCbR4F8p FFJrjH8QRVghDLu0JpJdha1X1pJzI3pS+A9jMUKvzwz81KC1iuP+I+y0fQ5YoqTUWhw5 s0oQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si16365313pjp.74.2019.07.25.06.55.13; Thu, 25 Jul 2019 06:55:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727772AbfGYMKc (ORCPT + 99 others); Thu, 25 Jul 2019 08:10:32 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:51555 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfGYMKc (ORCPT ); Thu, 25 Jul 2019 08:10:32 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hqcZp-00047K-JK; Thu, 25 Jul 2019 14:10:29 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1hqcZn-0006oY-6i; Thu, 25 Jul 2019 14:10:27 +0200 Date: Thu, 25 Jul 2019 14:10:27 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Stefan Roese Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Mika Westerberg , Andy Shevchenko , Yegor Yefremov , Greg Kroah-Hartman , Giulio Benetti Subject: Re: [PATCH 1/2 v9] serial: mctrl_gpio: Check if GPIO property exisits before requesting it Message-ID: <20190725121027.xc52wshky74wgebt@pengutronix.de> References: <20190620062420.11650-1-sr@denx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190620062420.11650-1-sr@denx.de> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Jun 20, 2019 at 08:24:19AM +0200, Stefan Roese wrote: > This patch adds a check for the GPIOs property existence, before the > GPIO is requested. This fixes an issue seen when the 8250 mctrl_gpio > support is added (2nd patch in this patch series) on x86 platforms using > ACPI. > > Here Mika's comments from 2016-08-09: > > " > I noticed that with v4.8-rc1 serial console of some of our Broxton > systems does not work properly anymore. I'm able to see output but input > does not work. > > I bisected it down to commit 4ef03d328769eddbfeca1f1c958fdb181a69c341 > ("tty/serial/8250: use mctrl_gpio helpers"). > > The reason why it fails is that in ACPI we do not have names for GPIOs > (except when _DSD is used) so we use the "idx" to index into _CRS GPIO > resources. Now mctrl_gpio_init_noauto() goes through a list of GPIOs > calling devm_gpiod_get_index_optional() passing "idx" of 0 for each. The > UART device in Broxton has following (simplified) ACPI description: > > Device (URT4) > { > ... > Name (_CRS, ResourceTemplate () { > GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, > "\\_SB.GPO0", 0x00, ResourceConsumer) > { > 0x003A > } > GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, > "\\_SB.GPO0", 0x00, ResourceConsumer) > { > 0x003D > } > }) > > In this case it finds the first GPIO (0x003A which happens to be RX pin > for that UART), turns it into GPIO which then breaks input for the UART > device. This also breaks systems with bluetooth connected to UART (those > typically have some GPIOs in their _CRS). > > Any ideas how to fix this? > > We cannot just drop the _CRS index lookup fallback because that would > break many existing machines out there so maybe we can limit this to > only DT enabled machines. Or alternatively probe if the property first > exists before trying to acquire the GPIOs (using > device_property_present()). > " > > This patch implements the fix suggested by Mika in his statement above. > > Signed-off-by: Stefan Roese > Reviewed-by: Mika Westerberg > Reviewed-by: Andy Shevchenko > Tested-by: Yegor Yefremov > Cc: Mika Westerberg > Cc: Andy Shevchenko > Cc: Yegor Yefremov > Cc: Greg Kroah-Hartman > Cc: Giulio Benetti > --- > v9: > - Rebased on top of "tty-next", patch 2/3 dropped as its already applied > > v8: > - Rebased on top of "tty-next" > > v7: > - Include to fix compile breakage on OMAP > > v6: > - No change > > v5: > - Simplified the code a bit (Andy) > - Added gpio_str == NULL handling (Andy) > > v4: > - Add missing free() calls (Johan) > - Added Mika's reviewed by tag > - Added Johan to Cc > > v3: > - No change > > v2: > - Include the problem description and analysis from Mika into the commit > text, as suggested by Greg. > > drivers/tty/serial/serial_mctrl_gpio.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c > index 39ed56214cd3..2b400189be91 100644 > --- a/drivers/tty/serial/serial_mctrl_gpio.c > +++ b/drivers/tty/serial/serial_mctrl_gpio.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > > #include "serial_mctrl_gpio.h" > > @@ -116,6 +117,19 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) > > for (i = 0; i < UART_GPIO_MAX; i++) { > enum gpiod_flags flags; > + char *gpio_str; > + bool present; > + > + /* Check if GPIO property exists and continue if not */ > + gpio_str = kasprintf(GFP_KERNEL, "%s-gpios", > + mctrl_gpios_desc[i].name); > + if (!gpio_str) > + continue; Is it a good idea to handle a memory allocation problem with a continue? > + present = device_property_present(dev, gpio_str); > + kfree(gpio_str); > + if (!present) > + continue; > Assuming this fixes the situation on x86 this means that there device_property_present(...) returns false and devm_gpiod_get_index_optional returns an error code. I wonder what the problem is here. Is CONFIG_GPIOLIB on in the failing situation? I assume this will end in the usual discussion if gpiod_get_*_optional should return an error code if GPIOLIB is off. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |