Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3609642pxb; Mon, 24 Jan 2022 13:27:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzATLrKL+3HG6qlxIm38F6BZK4M7y1bTkEvoUrzcT9f7fEZSCy4ke/tq0N0Bq4GQscR8CJ2 X-Received: by 2002:a17:90a:dc86:: with SMTP id j6mr267626pjv.52.1643059656110; Mon, 24 Jan 2022 13:27:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059656; cv=none; d=google.com; s=arc-20160816; b=aNOcVX6Xf8/6fkhkHdtHnlB3A0W1gcmZwJAFZ9eLLCI/mbDMKIW+dpH2mVdiN8wtZm KtJilL7vaWGeRaFCo/x1DE2hqV/L1vr1fPz8H9m1hOSXHXlwHfVVmXWQeZo9ovCb1+qC rdlKgASIlE6qlXGSLF2RoirI9cNRNhMwyNobSd/QUaPXtLxpfSIsL+fY94z7ZIOrehjt otZZIx2Yrek//5zBLBds65FZ+UHE7m9lQD6+NP24ip2aQ67iU3XX0br4kh1GvXilmHEb LNG57GTA/MQGfTU2VEC7UUGd32qiiCk+VVQguDcRHTsMx6jQTOAWnqXhOqSuoOkMO/0O YpCw== 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=eOtlLfA4a5Y1DnL4wUcYj5QqPXojMpf9IGzslDylIvQ=; b=GpxQxLVXXbJeS0IySXwoXNfiGVtdGzI1791862mrZjV6nJacE/RlbCDl6S6okbIYJT es84aZv/EYucJT+WLJZa1iTXac/yARsGMXJofXt1+zYvwYWMoJr+AQvTdn0QzZCutm2o YjXpQgcSmnqAEQK6Cym4tKVYAM2861q6XZcw1JDS5oxSrnPtgL7yH2AKvbmyW+8sR5a6 epovvilLWMa320cLtTszRycPBZriz72xPur64mH1gPs1ptUtXRcrCJYXl2X+FirIhsK/ Q8vuLC7sbT7hD5Jm6633DFtBAUN2AgRLhvBaNA0a8PpAzpHY463tHVFUorTzipqerDxO HxYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eCqV5qUo; 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 fw10si380879pjb.4.2022.01.24.13.27.23; Mon, 24 Jan 2022 13:27:36 -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=eCqV5qUo; 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 S1444517AbiAXVBF (ORCPT + 99 others); Mon, 24 Jan 2022 16:01:05 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:32830 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387681AbiAXUhD (ORCPT ); Mon, 24 Jan 2022 15:37:03 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B4F8E613FB; Mon, 24 Jan 2022 20:37:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98715C340E5; Mon, 24 Jan 2022 20:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056622; bh=p9CdwRWne9+kvQaj67kRPnickld1KZcHC6w7Wj/SdVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCqV5qUopPCpOwjq4HJzY8XvAmd1qM/oaegEyOGhx6A1vQZidnNnyo2QKswqw5taP BcLm/cLHBLetYIgs3uvDyE7HCgxYBoquIr0F6wO/phDwicizAUSfsszAdgFepvmzdx kDlnQJ86JDmQXWVgSXxc1SFCfzTo8Cn/SUB6uyME= 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.15 502/846] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Date: Mon, 24 Jan 2022 19:40:19 +0100 Message-Id: <20220124184118.350491813@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 47712b6903b51..d040c72fea582 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -1059,10 +1059,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