Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3622129pxb; Mon, 24 Jan 2022 13:43:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAYzF7o7XJnQRVKq2lRT8mwhKoRI2qnelfj0P5YwHHFvcjsx+HNRnOrrjc1T7ubHPguKAV X-Received: by 2002:a17:90b:17c4:: with SMTP id me4mr268239pjb.198.1643060624231; Mon, 24 Jan 2022 13:43:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060624; cv=none; d=google.com; s=arc-20160816; b=akisDue9sdoliSpq59ZUdyrmXJ7bx0SKIP+ke+Xgy2dBrU+4EFpk/4O3bEzKXzv4OX Alul1H9/cD+6oQPSn8xLpNfLuEUnZIlN2Dr1tBom8QnS6WLAsuyGzYvf47RvLk5jUiUO aKrQjZjWOA9vwiMa+Z4hrStp/8Bnbgfe3BFawJo+44k6594apvKHnqyOPyeppcUKt9jV UNZlkF9HkmJ2JWQhNyS3tl5OYeKv8c3/B0vyqF01GdgO7LM1dapqBTd4u3GgLe0fXZw2 xlowSMNZsAVAewEYLagNIDfzR26ZpOS7d3Vt9cQjOTYgLzNOzi3KuIl9hCKUwSkXzk1C dd/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9hoIGFJBrJhCTRnwvuavEAPP5CiKmfc1XCLvub+SXeg=; b=QbKaqG9WKan2k8gsQiOP+kVjruNrXEFE6cWhdlPvVQBkcDbM+XGe6c1OL6jiMpNigA FL7aGvxCxdJgxJra8rhzHSUtXQ+Nlg1aUlG4h5kHxL3KdFZ9Buvt6XEWPybTZYPZ8c+T jmhpOIN8J5S4evCN6eTafgA1ZVyWJsz0V8K8Bp8t/GD6hzZ8/grhzNoIdR/f3bBfevJR ww62zOM9HwXoZeuhKcracDfhsmSdNYaCxfppTsbkE7QqmPuD4pCql+6xS8kSIBTOEMKU 6fzrn4nevx9mYXIlOXmpo54nPjFZyt0bRHQBOlkSj+0cJRrFTSg3SYdlwURhC0yFcPg7 AIHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bdg/XbhF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pc9si452988pjb.67.2022.01.24.13.43.25; Mon, 24 Jan 2022 13:43:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bdg/XbhF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1451940AbiAXVXs (ORCPT + 99 others); Mon, 24 Jan 2022 16:23:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443258AbiAXU4e (ORCPT ); Mon, 24 Jan 2022 15:56:34 -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 272A6C07A94A; Mon, 24 Jan 2022 11:18:46 -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 E2D97B81238; Mon, 24 Jan 2022 19:18:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB59CC340E5; Mon, 24 Jan 2022 19:18:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051923; bh=M4UE480JwyzeOBq6t7B72Ees1unLdZDrfoZ7S9bjVYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bdg/XbhFrMJFdewhn/BIPQ++Wng3kND2otsxRKLFG0uBj+jF9tYH72GMYrPB7zaCF P2rkpsjLHhyvkhLeZxivi/6XRhvFbU/T29fSJVn425QrUE0ZhtQ9JAXwA1vrmAcWFj 5rjaGW5q9M5Ak+NvpEBShmcG2tDMwcyadP5WXZG4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Andy Shevchenko , Sasha Levin Subject: [PATCH 4.19 130/239] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Date: Mon, 24 Jan 2022 19:42:48 +0100 Message-Id: <20220124183947.242153916@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 b018909a4e46c..47cdc1f89e3fb 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -904,10 +904,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