From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB4BBC433F5 for ; Wed, 23 Feb 2022 21:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242485AbiBWVcP (ORCPT ); Wed, 23 Feb 2022 16:32:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242653AbiBWVcO (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 35C903C721 for ; Wed, 23 Feb 2022 13:31:45 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id a23so180762eju.3 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=QeKSCYgm3HL8ah+9t804cxYbglsPuu8Ykml6ubpgWQm8rUbeUOnVK4kKsBOVxyrw26 3GziEN98TJe497d0bG3OTXNlNoZU0ZKClBWQy3ZGafk8CtYB/lX2Vj/6pYBj1vso/3sw iVCl4swfk65dCzaHODZzX2XrCD6JRHEEMC8oxJCMiwT0+dvnBJjW884tSNOhEp8SFKGW QbziLl2gWvDStLahxfMZx7UGK+worYnUKsM0v+LIsRemX3l00F2r/hCPwcEkYO6NjlOB YN4ol8GEJMlrNd2UQJ93O2yscoFCf+qtGQvFc87Ym+PiXSFW/GPWQT3p5dlqfASM4Cec Xb6w== X-Gm-Message-State: AOAM531l66yQ691OOii6cI1kD5UKygN5AM+0giIBVLgPvpNdTCD9Isi2 Amrc6eFMPDGjqRI6VldO4GqhKiuv1XreDREHIu85udAVodU= X-Google-Smtp-Source: ABdhPJwGY42pBBzmTXzQxtK8kQ3OvjcZRZjenfG79d42ZtNsrmQbmI2eEfrJx7GQiFK4Ji4rSTRHC8jqjQ1/5CRtQ3s= 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" Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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