From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59509C433EF for ; Tue, 18 Jan 2022 03:17:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245534AbiARDRW (ORCPT ); Mon, 17 Jan 2022 22:17:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348690AbiARDI1 (ORCPT ); Mon, 17 Jan 2022 22:08:27 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 981CDC0612DF; Mon, 17 Jan 2022 18:50:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 59C0BB81195; Tue, 18 Jan 2022 02:50:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12AD5C36AEF; Tue, 18 Jan 2022 02:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642474203; bh=yraV5qbWzPsH0cRFfYvfm/iPTOmgkyD17b1bI7AU2sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kF/GqYPnIGrVj8uCkGcUMKItTUiajqIpO+zK3SiD2XXoDEfOvBRSCBuXAuwYAuK37 EOPX+ibyxcJByV8hmQOqnRtcfUC7iMbegaZhRR2eVKOYTqMIgoXLTMsG4BRY3ESCrq 7UR3sCSJWvAjYnVxr3ldrgNU3iBWPysNzGcPbhhZ/hAE4y+ziu+jfIkALabgUuaa6v rSrm34uMvu1QInNuA6Oj6y7vYfsZyZFl1PRnKFDIC2q4JedXu7acT7lsRc/fuM+KFS o1ZvC77585tgt7tLaJAex+FKt1rbI5yvlJXkcYCNZyDVSefhJlfkaen8i7RrmCGY86 5WJUkkF/b+dGA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hans de Goede , Andy Shevchenko , Sasha Levin , mika.westerberg@linux.intel.com, linus.walleij@linaro.org, brgl@bgdev.pl, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 19/56] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Date: Mon, 17 Jan 2022 21:48:31 -0500 Message-Id: <20220118024908.1953673-19-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118024908.1953673-1-sashal@kernel.org> References: <20220118024908.1953673-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Hans de Goede [ Upstream commit bdfd6ab8fdccd8b138837efff66f4a1911496378 ] If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really should not change the type underneath the current owner. I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay Trail tablet, when the Boot OS selection in the BIOS is set to Android. In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and the _CRS resources for this device include a GpioInt pointing to a GPIO already in use by an _AEI handler, with a different type then specified in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get() call done by the i2c-core-acpi.c code changing the type breaking the _AEI handler. Now this clearly is a bug in the DSDT of this tablet (in Android mode), but in general calling irq_set_irq_type() on an IRQ which already is in use seems like a bad idea. Signed-off-by: Hans de Goede Signed-off-by: Andy Shevchenko Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib-acpi.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index c380ce957d8da..60e394da97098 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -943,10 +943,17 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) irq_flags = acpi_dev_get_irq_type(info.triggering, info.polarity); - /* Set type if specified and different than the current one */ - if (irq_flags != IRQ_TYPE_NONE && - irq_flags != irq_get_trigger_type(irq)) - irq_set_irq_type(irq, irq_flags); + /* + * If the IRQ is not already in use then set type + * if specified and different than the current one. + */ + if (can_request_irq(irq, irq_flags)) { + if (irq_flags != IRQ_TYPE_NONE && + irq_flags != irq_get_trigger_type(irq)) + irq_set_irq_type(irq, irq_flags); + } else { + dev_dbg(&adev->dev, "IRQ %d already in use\n", irq); + } return irq; } -- 2.34.1