Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3643220pxb; Mon, 24 Jan 2022 14:14:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxn6VzTXKCRtvG0RZcrolfCH3mF44g9MFz/oodRzQ0FVJ4b06A6zkrtpJPU6vpNd1FGkypi X-Received: by 2002:aa7:8ed1:0:b0:4ca:c47f:552e with SMTP id b17-20020aa78ed1000000b004cac47f552emr281010pfr.6.1643062483901; Mon, 24 Jan 2022 14:14:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062483; cv=none; d=google.com; s=arc-20160816; b=uLe8H99pbxaCFjLwBFGsVgZiNjEsnlbJAN2z8hotGcrvHLJgUV8nnzJJzH56xP/Bgc jMssu8c2XcUL8cAHgxip7tPUB06PGV0yko+x7srd0wtui3CirjlYK6oo4ePXAGudbjib RqK3AVe59QJUn+DYoKg/JMQazCNHSKF//Yy4PcIyTqwHiLivbBUOcx9DSPdG/RjtTL0l SCbgixR5vb7d++tp6jlGZLQTxgP+NQhnuPTOI5JzMNLOP74LrlSkKPp1OtCyAxQBv+Jh +8I/+i9T68qkwusFBQbJvIJaxalccMFjgmIowiN1j09Ssuxjf13fm4AOubIYSDqSZ8Rc JPhg== 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=kOscn/DcuXQvsBZ2s5bjAdsWqvXHTRjPP0DsO98ywas=; b=oYfJ316gyC3cfsVKGa5b0ZNdYBHjjeoTD8L5u0x0hGMwIDonNFDrPSIiK3eaI1LbvC 9IWppMSqzPFyX5aXarvoUBumdlfuDC0hT661gxLP+H5her3St41dB7xAVwBN93Bc8mZ/ Ejz9DXq53G5a/i/7trNYzti+4ETlv9BwvAG9sqdJ8WfjVw/4zyKK2lB84ik8/CSkGE47 fgZJjH5LUoqOeh2e8YFILwY25XfKssN7SsAaAl5AcjBj5kZxzLdrytz30d4DgyBXDua6 xXcCBNAi85GmcEnrjyYjUw1VCAQ9HnQSTr+gzl7AJg552zoOYMVfEppvt4f259DVrLev MP6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FqU7ZrHp; 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 w10si13901466plq.346.2022.01.24.14.14.26; Mon, 24 Jan 2022 14:14:43 -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=FqU7ZrHp; 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 S1577454AbiAXWAO (ORCPT + 99 others); Mon, 24 Jan 2022 17:00:14 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:40148 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1451392AbiAXVWu (ORCPT ); Mon, 24 Jan 2022 16:22:50 -0500 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 49B77B811A2; Mon, 24 Jan 2022 21:22:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A4FAC340E4; Mon, 24 Jan 2022 21:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059368; bh=jq5nSyDGNO8hpQ1IHIdwhL+JRSQlm2E4xpGYFSvtRJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqU7ZrHpMZncOpa2qg62N8MRZ/5COfN4PMKusEQQPWhcjnWMsqrEPRWmnAjtbgKFJ iY//4SfUkPIhg0wZ6+GRAqrBAHYSzqGQvyRP+51ku/GN2WRuYkAq8EZu4Tu9/OiZg/ ym1XNhDjOQQ3bV8fyFAFpQGQtwFTR00DiEnhCTTI= 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 5.16 0593/1039] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Date: Mon, 24 Jan 2022 19:39:42 +0100 Message-Id: <20220124184145.265483102@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 985e8589c58ba..feb8157d2d672 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; } -- 2.34.1