Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp955833pxp; Wed, 16 Mar 2022 22:34:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG2X4N1SSJ3yu+XLc7VdzLVxztp7JyZy2fpXzaqpT9hRh4bsgbRtBJi3b5nPl6V0FUMl7k X-Received: by 2002:a63:4e14:0:b0:374:4a37:4966 with SMTP id c20-20020a634e14000000b003744a374966mr2394817pgb.118.1647495257986; Wed, 16 Mar 2022 22:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647495257; cv=none; d=google.com; s=arc-20160816; b=JdYD8lVSWiJv/OrU6KWQazum7eUPOQHnxZpzYA5IqHMIeP+lXP5WqQ21xDKBb8Gnv+ P6D36gTBNCrgPsDmuQm5mmOKHfwmB9VApdWHkK1irJxdK6W+iUL9ADuLAowKtMtd68a9 B4d9DNbHW++cbCZs1qoRBXlBChgwnFoS+qyawD+NF6yLDX6XvtNzRAEpWecwvsl3WzK5 SpwsPYzk1RfQd8dM2O0Z5hVsr9GWC4QItow/cGK0YbWBAfRczcHZ6+V8UfSVN/HK6woY n7K7ZjcNLRPSpf8KD1lHq1ACn8z8VbgrAPld3mb0IwkbIdQQC1SQIGd84yMmctbjb0Nz 5HKw== 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=LEwr3Pq8OLi23abafR16r/v1vkaf/GZ0jPsIJQAxMBQ=; b=knz1ETI/Dnml2mr3zaDMXxLIdgAuFXzIJ3SelSf1dE7HYwqvhxRT8E0mjWiy7YehE8 twBv/UAaj1gWY2JjDeaeBlsZo5rfIhQPY/ml/pr+ZrXQk/LI148jVCg1fsQRadWadmUH E+sQrfru2IAMCQpKGGn9O1ihnkzbA6iBfmSNieLDuiJSmGDw6yNCAPh0Wnzrdd9y0VCb qbGQc0nhpjU/LgaNFKbUE1lJW9+EUeuf74qgaAXbIHEPTNigunx9H8oFRLmw1sRnVJtD HPEINVH6HblyvrJoezci1lmBuMY3JqjGM4xKA0WrV+uTvz9MuJPUJrF0uoEK7mkTEMTm 22fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ILbsmcwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b9-20020a637149000000b003816043ef97si1082773pgn.396.2022.03.16.22.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:34:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ILbsmcwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1961100E04; Wed, 16 Mar 2022 21:37:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244204AbiCNMbp (ORCPT + 99 others); Mon, 14 Mar 2022 08:31:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243473AbiCNMUp (ORCPT ); Mon, 14 Mar 2022 08:20:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B218546A1; Mon, 14 Mar 2022 05:16:08 -0700 (PDT) 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 D383860929; Mon, 14 Mar 2022 12:16:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E2EBC340E9; Mon, 14 Mar 2022 12:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260167; bh=ElunhrL+NnN9HybiB6bM+2vs16utvqSOjpdCWcmh+X4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILbsmcwL0XQkXwNPlMAHJt6GMHJaJ+NFWXTSPifAGjS61fFoB7hSo1ZsU5Cn2AK1Y RVI4W/s4hC2+2mnT2f3P3bA/sPl8x6KLBdowweulBLIbpPLkYK0P84zdE9XKQ/+WtM 5mCq1f7YVXC0F+YvX27xzAmmk6VlmZNAc4QCc2k4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Walleij , Andy Shevchenko , kernel test robot , Shreeya Patel , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.16 076/121] gpio: Return EPROBE_DEFER if gc->to_irq is NULL Date: Mon, 14 Mar 2022 12:54:19 +0100 Message-Id: <20220314112746.242564960@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shreeya Patel [ Upstream commit ae42f9288846353982e2eab181fb41e7fd8bf60f ] We are racing the registering of .to_irq when probing the i2c driver. This results in random failure of touchscreen devices. Following explains the race condition better. [gpio driver] gpio driver registers gpio chip [gpio consumer] gpio is acquired [gpio consumer] gpiod_to_irq() fails with -ENXIO [gpio driver] gpio driver registers irqchip gpiod_to_irq works at this point, but -ENXIO is fatal We could see the following errors in dmesg logs when gc->to_irq is NULL [2.101857] i2c_hid i2c-FTS3528:00: HID over i2c has not been provided an Int IRQ [2.101953] i2c_hid: probe of i2c-FTS3528:00 failed with error -22 To avoid this situation, defer probing until to_irq is registered. Returning -EPROBE_DEFER would be the first step towards avoiding the failure of devices due to the race in registration of .to_irq. Final solution to this issue would be to avoid using gc irq members until they are fully initialized. This issue has been reported many times in past and people have been using workarounds like changing the pinctrl_amd to built-in instead of loading it as a module or by adding a softdep for pinctrl_amd into the config file. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=209413 Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko Reported-by: kernel test robot Signed-off-by: Shreeya Patel Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a1dca6dc03b4..dcb0dca651ac 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3121,6 +3121,16 @@ int gpiod_to_irq(const struct gpio_desc *desc) return retirq; } +#ifdef CONFIG_GPIOLIB_IRQCHIP + if (gc->irq.chip) { + /* + * Avoid race condition with other code, which tries to lookup + * an IRQ before the irqchip has been properly registered, + * i.e. while gpiochip is still being brought up. + */ + return -EPROBE_DEFER; + } +#endif return -ENXIO; } EXPORT_SYMBOL_GPL(gpiod_to_irq); -- 2.34.1