Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3622777pxb; Mon, 24 Jan 2022 13:44:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg6u5eck3K74Foe4s3nIUsFinC7vQNvByukBC4UHpFCxx0M3xnruc0h0gQ3mIWqz9pNYkA X-Received: by 2002:a17:902:9884:b0:14a:c885:720a with SMTP id s4-20020a170902988400b0014ac885720amr16123055plp.68.1643060591296; Mon, 24 Jan 2022 13:43:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060591; cv=none; d=google.com; s=arc-20160816; b=JnJnHlLEuXWR+6YqSWCfDfyICRtGFAUn/kr8lTuWdUzoN67clsJa/0Cg91hLLl2ome G4E/nvaNlfHS/M50VgGoS4Vaq+M+Aahyi+waTuiXEaiV/HNRtwpCmELYWo0chuXgwv56 EFvCq4qNV3kpEXZnuIhJIyUJATBdiYge+savb4QYulh+JbE4cFF98g0g+yEn0KDHbT/r G4+jJq3Xsqx2A2VIu8vdVnNB8FLkdVeg4p+IkXgwwsddi8stMvQtpjJvwoqI9Wq27Pii jiFCBtEL6vo2fOn4FX+RqH2QvxioqL+HYpS79zjXqUIRukWt6Rt0BmPU4cqEsciMYtdx PA5g== 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=jdKWD+6Nt3REU4JlMeM0OC72YkfmFl5PdFI0nu9YUeM=; b=bn75TfEDH1c0Y1y+3u2QDsp+W6AezmCHqAv/pldNcwebbFBX23uepFlJFuF6g9p8ra QmNUu1Jhm3xa/5ncDJlOcj6dJ0jOiwsA0+kARVgqckNffKsLOgh5OxKGGUECDXYTetvE jVv3qumpwyunoFbqo+fZddB7lM/fhZrUlKa4k7ZFFqTJPXFHtskpzy9OEoilOilorBHW NcIS2CmullZKW5/HKBMSPML390dTJYCr7i51d8OeepGzBLSsCpMdKjYMwDPt8gL68jq3 dmN4Ps7E9N5hbqPQmfcHV6Zf4WnvqiaH4k07z3oNdlczwQIUebZWm1469qcLjSNcPhyS PSmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AKHwK+2M; 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 83si7023758pgc.454.2022.01.24.13.42.59; Mon, 24 Jan 2022 13:43:11 -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=AKHwK+2M; 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 S1451233AbiAXVWa (ORCPT + 99 others); Mon, 24 Jan 2022 16:22:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359039AbiAXUxE (ORCPT ); Mon, 24 Jan 2022 15:53:04 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E109FC095401; Mon, 24 Jan 2022 11:59:04 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6A5FE60FF4; Mon, 24 Jan 2022 19:59:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EB2DC340E5; Mon, 24 Jan 2022 19:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054343; bh=fpJUuwgTvCrd7e1pIEnOTkVUhstiH0I4N60wi49/f9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AKHwK+2MT5AU80uYTa7yjfdtJgSPMVFf8NB5OfkM7PJ+BKATRL1rHoNgWcRlc+yJG wfsJbA9hBkabcm4ceFwU//lkPVqPX8J7OIrKqrxdjmY2OkKDGtc26WGiyXRJysBKq0 27jbOOh9Ay/kUVhsz0DGgBJ4AAbtXAC2HpMgbDx8= 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.10 325/563] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Date: Mon, 24 Jan 2022 19:41:30 +0100 Message-Id: <20220124184035.676435963@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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 6f11714ce0239..55e4f402ec8b6 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -969,10 +969,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