Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1047545pxm; Wed, 23 Feb 2022 16:47:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpQocKK9tDFeeAjmnw+PnwdeoIakSl3w7XQebSIDz1CZ9zW/cuyGlkG37WCd8KzFLuhjE6 X-Received: by 2002:a17:90a:430b:b0:1b9:495c:90d0 with SMTP id q11-20020a17090a430b00b001b9495c90d0mr187991pjg.81.1645663670944; Wed, 23 Feb 2022 16:47:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645663670; cv=none; d=google.com; s=arc-20160816; b=EQl87Cx3OCxZAvBfcXdrPYnaDRdbyFkXbUF5d3Vxf/vtO8TFtHpQkW8AUXpu4VYO3X diQ8lvwcQA0TS2vOyR6xybR6cKvwlCHN9dzak/MVXVXRHe/9y3TjTdtCoRtMinDNzZbf rmHDYHf0yL3jXx/iX1z+c3Agi8Vzj3cGsyzUeACXcJ2gatq/xP29ly/8bvJSYLLToYkQ TEODFlQOuw7wgsAkZJy+aLivqMlqZ6678IuX6URvh3KUpV+9Hn6gOFVPaajomy3xiCNC RAqxRK87g2/0LTFf+xrEu4K9QgFoz0Z1DTgGe4xWwLpz/wZsfH9BW5QMylXIPuQI8X3M QU3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Z4ZVkt8qZMy2gYEg/eldrrEE9UadTptB/fCse20u77k=; b=HCyZwGa927SG5/OETNDywS5XISBdPk5mkRSku4Lb4pq2W3wBH6GJ3Lxy7pRc2hVDFS Rx0pSgWKovJJtj1iR5FnvMJX8O7SEaNgn9hNyPK2ydhH/buKRd57YQa0qEeEeEs5lbeK aW8guOSabgCoiPhryMQMuONZzGfnT+E5gfqqB+mBqyZKzsdlaO8hCIQW2fKN5l4Di53Y lcGj3V/ueetOj+TMUCHUybgBtMDjmYKf6BzZrN6m61EjFYkwieFIk0LtyWFKeaOZWpMa D9p1x3mIQY/lgNgBSdeC2JaPP4NAIYAeJ12TnG/mAcczqua9LczUINVF6eRWzh4vfCcq ERNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=uH3iTz2Q; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m20si951273pfk.319.2022.02.23.16.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 16:47:50 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=uH3iTz2Q; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 42BAA3D49E; Wed, 23 Feb 2022 16:43:05 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242666AbiBWVcQ (ORCPT + 99 others); Wed, 23 Feb 2022 16:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234865AbiBWVcO (ORCPT ); Wed, 23 Feb 2022 16:32:14 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369E03CA49 for ; Wed, 23 Feb 2022 13:31:45 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id hw13so124396ejc.9 for ; Wed, 23 Feb 2022 13:31:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z4ZVkt8qZMy2gYEg/eldrrEE9UadTptB/fCse20u77k=; b=uH3iTz2QGOOXGOs7gP4GUWmAmCSbm7JwqXRf/KvtFUe2MV934uQIEoIMfozDrL5ffI trMtsQ83jy0lfEhG5pRbtwCDZ9MRFRvNXLlAx8KIx7JlIU0C4uSOG2+dfonx4pBCMZc5 lCttbFooWLazs/0fKKgsXUpOI2xQxA6W88Zyb/Vlu1KxU+IXRnQtmiE1gk4negHvoB// CLuSgzLmqazAqFFZnawz8ktkav2/oByCKPSNbfqx6/W5e3Lkmg+5Z0w/Hs9akdqYS5OW SGNTWMWIQzdkDoiX3xmdCm2Vc/yiUYSRWYfP6I7nYvtSi5AsYULM0LBXA/yKyVubEDjQ zZ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z4ZVkt8qZMy2gYEg/eldrrEE9UadTptB/fCse20u77k=; b=A5miXaqjPmoqG6LdEXZddRk18FGp7xyjDYRJMoxmMLFBTTbceUiCmmVjw0Pi3PupAr aFdtsgVe3wg05wH6ViCvHtPtk2Zm1K8/q+P0ijI9NTLiErbnXxpts6pC1dcH2HcBN0V/ J3wgxG/6nmZK73DqM3dWkyjcQ1vL5drit+/t4EXpGMlREykCIetZpUDvulL3663Jr6ub n9sf+Eq8MR2LfhpMNFoHANIu4jP/MNw1/2rCv1PcZ09Ohh80P5bzoDbCLf4Ag2eZz8jX CYll1UBthYWUw2Y2Xz7uaji0a8BJs8micgMIFoF+JfSySAwErVvyOKnhwMMBGrykAN/E P8QQ== X-Gm-Message-State: AOAM5312UMkIOFxmaJ2ltFM7pGPWXNsFMrtp/qjmT7szvpxT6tqTrUFe HEw8uQHbOuHp+Q5COk1Q8tL7JJjA2Cu9e4AJhC6UwQ== X-Received: by 2002:a17:906:1393:b0:6ba:dfb1:4435 with SMTP id f19-20020a170906139300b006badfb14435mr1282305ejc.736.1645651903755; Wed, 23 Feb 2022 13:31:43 -0800 (PST) MIME-Version: 1.0 References: <20220216202655.194795-1-shreeya.patel@collabora.com> In-Reply-To: <20220216202655.194795-1-shreeya.patel@collabora.com> From: Bartosz Golaszewski Date: Wed, 23 Feb 2022 22:31:33 +0100 Message-ID: Subject: Re: [PATCH v5] gpio: Return EPROBE_DEFER if gc->to_irq is NULL To: Shreeya Patel Cc: Linus Walleij , Bartosz Golaszewski , Gabriel Krisman Bertazi , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , kernel@collabora.com, Andy Shevchenko , kernel test robot Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Wed, Feb 16, 2022 at 9:27 PM Shreeya Patel wrote: > > 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 > > --- > Changes in v5 > - Improve explanation in commit message and sending it to the correct > email address. > > Changes in v4 > - Remove blank line and make the first letter of the sentence > capital. > > Changes in v3 > - Fix the error reported by kernel test robot. > > Changes in v2 > - Add a condition to check for irq chip to avoid bogus error. > --- > drivers/gpio/gpiolib.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 3859911b61e9..a3d14277f17c 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -3147,6 +3147,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.30.2 > Queued for fixes, thanks! Bart