From patchwork Thu Nov 25 20:30:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12639807 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 21AB6C433F5 for ; Thu, 25 Nov 2021 20:32:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238267AbhKYUfb (ORCPT ); Thu, 25 Nov 2021 15:35:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:55887 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243358AbhKYUda (ORCPT ); Thu, 25 Nov 2021 15:33:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637872218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=15X0PZ7A6XKo5iJl7JpnvPkArj6Rdd+x2l/76fDUKD8=; b=a31CpIWWSpqjY7Y5HnNxrjTQ2n6W4PN2ZSXzSvGWXdEVjztkgxYcx8T0is2vGJGZ6R10yj PXPM6rV2noSOjnnO4Z3EbhgXbEGYSIj6qQJlwsRyJ1fWsTWM5ucL54qIhA3bRQ5PnC/55h 6DAmfBdttGkPwzwCB4cnklioH2FJxE0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-25-nfizcVc2NMKKzXEhrYQpZA-1; Thu, 25 Nov 2021 15:30:14 -0500 X-MC-Unique: nfizcVc2NMKKzXEhrYQpZA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7DE50102CB2A; Thu, 25 Nov 2021 20:30:13 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.195.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id B296C7945A; Thu, 25 Nov 2021 20:30:11 +0000 (UTC) From: Hans de Goede To: Mika Westerberg , Andy Shevchenko , Linus Walleij Cc: Hans de Goede , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Date: Thu, 25 Nov 2021 21:30:10 +0100 Message-Id: <20211125203010.825442-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 --- Changes in v2: - Emit a dev_dbg when the IRQ is already in use. Note while making this change I realized that i2c-multi-instantiate.c actually uses acpi_dev_gpio_irq_get_by() with shared interrupts, so I decided to go with a dev_dbg instead of a dev_warn after all --- 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 985e8589c58b..feb8157d2d67 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -1056,10 +1056,17 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind 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; }