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 CFAC8C636D6 for ; Sat, 4 Feb 2023 22:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232576AbjBDWcv (ORCPT ); Sat, 4 Feb 2023 17:32:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbjBDWcu (ORCPT ); Sat, 4 Feb 2023 17:32:50 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48F42234E9 for ; Sat, 4 Feb 2023 14:32:43 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id m13so8667816plx.13 for ; Sat, 04 Feb 2023 14:32:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TCubKHsyMQJF8LMl1XgSOrfeBF7lBTY/RGmJLycWlaU=; b=G2+vuASwFpuwWTpilhz1IvtVsiUT9WhCHPg3bHDt/5F+ZoUeYQwXI0GHaH/YaKtytT o1acMo5Mlm9cllOyD5PirVkDAsyvv3CP6uyWR+LaTPS1ROgZi0SnUgG8oPPxwGDdvf2H Luf92Ex8l5lVs6qa9X7drp1/LtoiKUv6uQViswIbJn67mpOnBEQ7U8Nir6vHJjl4A/oJ +5ukHAB+inYG8Le10OO2jEj7EmNeHwW7lkjz8nuxXrYC+JIa5v+c8qtK+v9w+HDq7apx KU2y4mG6YSECFfteheftSjttr13wzYo3LIzXiFwWhQHZEs641AvyDiOb9vOPwrpjxbKw BE5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TCubKHsyMQJF8LMl1XgSOrfeBF7lBTY/RGmJLycWlaU=; b=6EnZNDVi38b/ta44sXBhClB8owLct45COm5CrTeL11JO6tab8v3LlwnMnDb862Un9H wRoi9mTFowVkhy/EsLF/9Zu0XPluUAEPh99MGHsKf+PLpI7MJF8glzDJujatrBAI9vH7 0RF6+lRX9q/urSeAXlHvafbEvyArhY/bZiklPHgqL2yiAHaTcUmFyTXWLFt6s+cwQK/s 1XxWD5am3S1B/Fu33cSsDBasvqblpFlzu0kw7NpgN4o9cijS2hUIxc2uHvwJTAdc9FkU I+IuhkmmTD163pPp5na32cGafKnRVg9zw0WgfXHP3WNT716NeFWGpTNfY3qPg2kr188H 9pVg== X-Gm-Message-State: AO0yUKWcMUXDDrUUbB061HfHsJ7ONKsD0bgl1TGtiGpY98ydUKh7IKVp eaZzk0Un9ekOBwuQscvWpANE+CoqLCsEDbnFAITb+w== X-Google-Smtp-Source: AK7set+WTHxq5oO63yGH1Y9Xnzv5N1lAd2jXSDL3AuczoyplN2Tu7uL6IRfi3QFZwCS/cMVnCxbzD3B8jbvtM9uZpe8= X-Received: by 2002:a17:90a:656:b0:226:cff8:6472 with SMTP id q22-20020a17090a065600b00226cff86472mr2232226pje.73.1675549962139; Sat, 04 Feb 2023 14:32:42 -0800 (PST) MIME-Version: 1.0 References: <20230127001141.407071-1-saravanak@google.com> <20230127001141.407071-5-saravanak@google.com> <20230130143153.67dsxn4lugfetfwb@bogus> <20230131101337.376mnrvhltbsychd@bogus> In-Reply-To: <20230131101337.376mnrvhltbsychd@bogus> From: Saravana Kannan Date: Sat, 4 Feb 2023 14:32:05 -0800 Message-ID: Subject: Re: [PATCH v2 04/11] gpiolib: Clear the gpio_device's fwnode initialized flag before adding To: Sudeep Holla Cc: Andy Shevchenko , Greg Kroah-Hartman , "Rafael J. Wysocki" , Cristian Marussi , Linus Walleij , Bartosz Golaszewski , Thomas Gleixner , Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Rob Herring , Frank Rowand , Geert Uytterhoeven , Magnus Damm , Len Brown , Daniel Scally , Heikki Krogerus , Sakari Ailus , Tony Lindgren , Linux Kernel Functional Testing , Naresh Kamboju , Abel Vesa , Alexander Stein , Geert Uytterhoeven , John Stultz , Doug Anderson , Guenter Roeck , Dmitry Baryshkov , Maxim Kiselev , Maxim Kochetkov , Miquel Raynal , Luca Weiss , Colin Foster , Martin Kepplinger , Jean-Philippe Brucker , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-acpi@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Tue, Jan 31, 2023 at 2:13 AM Sudeep Holla wrote: > > On Mon, Jan 30, 2023 at 08:01:17PM -0800, Saravana Kannan wrote: > > On Mon, Jan 30, 2023 at 7:14 AM Andy Shevchenko > > wrote: > > > > > > On Mon, Jan 30, 2023 at 02:31:53PM +0000, Sudeep Holla wrote: > > > > On Thu, Jan 26, 2023 at 04:11:31PM -0800, Saravana Kannan wrote: > > > > > Registering an irqdomain sets the flag for the fwnode. But having the > > > > > flag set when a device is added is interpreted by fw_devlink to mean the > > > > > device has already been initialized and will never probe. This prevents > > > > > fw_devlink from creating device links with the gpio_device as a > > > > > supplier. So, clear the flag before adding the device. > > > > > > ... > > > > > > > > + /* > > > > > + * If fwnode doesn't belong to another device, it's safe to clear its > > > > > + * initialized flag. > > > > > + */ > > > > > + if (!gdev->dev.fwnode->dev) > > > > > + fwnode_dev_initialized(gdev->dev.fwnode, false); > > > > > > > > This is the one causing the kernel crash during the boot on FVP which > > > > Naresh has reported. Just reverted this and was able to boot, confirming > > > > the issue with this patch. > > > > > > I'm wondering if > > > > > > if (!dev_fwnode(&gdev->dev)->dev) > > > fwnode_dev_initialized(&dev_fwnode(gdev->dev), false); > > > > > > works. > > > > No, that won't help. The problem was that with arm32, we have gpio > > devices created without any of_node or fwnode. So I can't assume > > fwnode will always be present. > > > > Correct, and this one is not even arm32. But it is just reusing a driver > that needs to be supported even on arm32. > > Not sure on how to proceed. As a simple way to check, I added a NULL check > for fwnode building on top of Andy's suggestion[1]. That works. > > Also the driver in question on arm64 FVP model is drivers/mfd/vexpress-sysreg.c > mfd_add_device() in drivers/mfd/mfd-core.c allows addition of devices without > of_node/fwnode. I am sure returning error like[2] will break many platforms > but I just wanted to confirm the root cause and [2] fixes the boot without > NULL check for fwnode in gpiochip_setup_dev(). > > Hope this helps. Thanks for debugging it for me Sudeep. Incorporated into my v3. -Saravana > > -- > Regards, > Sudeep > > [1] > > -->8 > diff --git i/drivers/gpio/gpiolib.c w/drivers/gpio/gpiolib.c > index b23140c6485f..e162f13aa2c9 100644 > --- i/drivers/gpio/gpiolib.c > +++ w/drivers/gpio/gpiolib.c > @@ -577,13 +577,15 @@ static void gpiodevice_release(struct device *dev) > static int gpiochip_setup_dev(struct gpio_device *gdev) > { > int ret; > + struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); > > /* > * If fwnode doesn't belong to another device, it's safe to clear its > * initialized flag. > */ > - if (!gdev->dev.fwnode->dev) > - fwnode_dev_initialized(gdev->dev.fwnode, false); > + if (fwnode && !fwnode->dev) > + fwnode_dev_initialized(fwnode, false); > + > ret = gcdev_register(gdev, gpio_devt); > if (ret) > return ret; > > [2] > > -->8 > > diff --git i/drivers/mfd/mfd-core.c w/drivers/mfd/mfd-core.c > index 16d1861e9682..3b2c4b0e9a2a 100644 > --- i/drivers/mfd/mfd-core.c > +++ w/drivers/mfd/mfd-core.c > @@ -231,9 +231,11 @@ static int mfd_add_device(struct device *parent, int id, > } > } > > - if (!pdev->dev.of_node) > + if (!pdev->dev.of_node) { > pr_warn("%s: Failed to locate of_node [id: %d]\n", > cell->name, platform_id); > + goto fail_alias; > + } > } > > mfd_acpi_add_device(cell, pdev); > 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82DD4C61DA4 for ; Sat, 4 Feb 2023 22:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WyA6C/8hyyT6+BaM/MZuH2OWcIAplHZJdvemwaIm48Q=; b=LxfLpHEMyKJ+T2 l+E6JtIrHH0pu9GeNI/TR+6VPsQT/HfaPMZXpEP/DM8C378/xJ0YKkeQOaGTxH7Fp+kPtPucEHgb0 p5b4SJR+nhWyb3j+ZmIc48RTtb+nn9YMyggjt20AMRNHK21oMq6b53m78jiAI/f5NfpfgYcLXwRrK TDmvDYn1jlXYKOtaQ1WSmozQWQ2C3DFk3DKSuoN/yS573Y07+E7dwU0X/H1RlY/T4rEDrKBwTgEOm dL535JCWWbmGQU8aTy0ZhdoZFca12cnNdokiwh9x6pwTTYzOyQ2rP6ovg1y3dF0FZ4U5PIboEnQTe mzZFyCJ78Fj3WiRTDZOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pOR5V-005deC-Gx; Sat, 04 Feb 2023 22:32:49 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pOR5S-005ddG-CE for linux-arm-kernel@lists.infradead.org; Sat, 04 Feb 2023 22:32:47 +0000 Received: by mail-pj1-x1034.google.com with SMTP id mi9so8345323pjb.4 for ; Sat, 04 Feb 2023 14:32:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TCubKHsyMQJF8LMl1XgSOrfeBF7lBTY/RGmJLycWlaU=; b=G2+vuASwFpuwWTpilhz1IvtVsiUT9WhCHPg3bHDt/5F+ZoUeYQwXI0GHaH/YaKtytT o1acMo5Mlm9cllOyD5PirVkDAsyvv3CP6uyWR+LaTPS1ROgZi0SnUgG8oPPxwGDdvf2H Luf92Ex8l5lVs6qa9X7drp1/LtoiKUv6uQViswIbJn67mpOnBEQ7U8Nir6vHJjl4A/oJ +5ukHAB+inYG8Le10OO2jEj7EmNeHwW7lkjz8nuxXrYC+JIa5v+c8qtK+v9w+HDq7apx KU2y4mG6YSECFfteheftSjttr13wzYo3LIzXiFwWhQHZEs641AvyDiOb9vOPwrpjxbKw BE5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TCubKHsyMQJF8LMl1XgSOrfeBF7lBTY/RGmJLycWlaU=; b=EzEEO127T6UjnZC5PyinherAGSaGLryZQTL2qMeSQNtR517hIcbHM7eGQ8hdJp4vaP ENUME2lilW/cxcYUHtvdwmdNX5lkn1Y3plXZZlCiWs0eKUJKcD4c64TNRD8JF8qPYZwf LLJdrMe2f+QZbNDwvC5YFgqjk2T7K0frAe4fqHmeM9ajmGCRh6nW+sBJsyI3XnkGPIhz FjNMMcBT3F74eUi5ieHF4O1qZEiADaOwxPTLAv+lHFbpM9hytRGFuZ/CmZSfcoiHPuYr kISvQ6ss/+2r1uHNH9JshSL3R7LzYJePLdlvsbzfo4/VwCBmphxKxs+c58sLtPSRvaJF sTaw== X-Gm-Message-State: AO0yUKUgRPpZpL4ytDaHC9ONDAXvCgVUYMoX+2cO3UI4cpHd1JDL5Egf /iHzuakixSguwSy/kixzT3tcc/w7ya4chdgQAShAUQ== X-Google-Smtp-Source: AK7set+WTHxq5oO63yGH1Y9Xnzv5N1lAd2jXSDL3AuczoyplN2Tu7uL6IRfi3QFZwCS/cMVnCxbzD3B8jbvtM9uZpe8= X-Received: by 2002:a17:90a:656:b0:226:cff8:6472 with SMTP id q22-20020a17090a065600b00226cff86472mr2232226pje.73.1675549962139; Sat, 04 Feb 2023 14:32:42 -0800 (PST) MIME-Version: 1.0 References: <20230127001141.407071-1-saravanak@google.com> <20230127001141.407071-5-saravanak@google.com> <20230130143153.67dsxn4lugfetfwb@bogus> <20230131101337.376mnrvhltbsychd@bogus> In-Reply-To: <20230131101337.376mnrvhltbsychd@bogus> From: Saravana Kannan Date: Sat, 4 Feb 2023 14:32:05 -0800 Message-ID: Subject: Re: [PATCH v2 04/11] gpiolib: Clear the gpio_device's fwnode initialized flag before adding To: Sudeep Holla Cc: Andy Shevchenko , Greg Kroah-Hartman , "Rafael J. Wysocki" , Cristian Marussi , Linus Walleij , Bartosz Golaszewski , Thomas Gleixner , Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Rob Herring , Frank Rowand , Geert Uytterhoeven , Magnus Damm , Len Brown , Daniel Scally , Heikki Krogerus , Sakari Ailus , Tony Lindgren , Linux Kernel Functional Testing , Naresh Kamboju , Abel Vesa , Alexander Stein , Geert Uytterhoeven , John Stultz , Doug Anderson , Guenter Roeck , Dmitry Baryshkov , Maxim Kiselev , Maxim Kochetkov , Miquel Raynal , Luca Weiss , Colin Foster , Martin Kepplinger , Jean-Philippe Brucker , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-acpi@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230204_143246_442734_BF00A8E1 X-CRM114-Status: GOOD ( 38.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jan 31, 2023 at 2:13 AM Sudeep Holla wrote: > > On Mon, Jan 30, 2023 at 08:01:17PM -0800, Saravana Kannan wrote: > > On Mon, Jan 30, 2023 at 7:14 AM Andy Shevchenko > > wrote: > > > > > > On Mon, Jan 30, 2023 at 02:31:53PM +0000, Sudeep Holla wrote: > > > > On Thu, Jan 26, 2023 at 04:11:31PM -0800, Saravana Kannan wrote: > > > > > Registering an irqdomain sets the flag for the fwnode. But having the > > > > > flag set when a device is added is interpreted by fw_devlink to mean the > > > > > device has already been initialized and will never probe. This prevents > > > > > fw_devlink from creating device links with the gpio_device as a > > > > > supplier. So, clear the flag before adding the device. > > > > > > ... > > > > > > > > + /* > > > > > + * If fwnode doesn't belong to another device, it's safe to clear its > > > > > + * initialized flag. > > > > > + */ > > > > > + if (!gdev->dev.fwnode->dev) > > > > > + fwnode_dev_initialized(gdev->dev.fwnode, false); > > > > > > > > This is the one causing the kernel crash during the boot on FVP which > > > > Naresh has reported. Just reverted this and was able to boot, confirming > > > > the issue with this patch. > > > > > > I'm wondering if > > > > > > if (!dev_fwnode(&gdev->dev)->dev) > > > fwnode_dev_initialized(&dev_fwnode(gdev->dev), false); > > > > > > works. > > > > No, that won't help. The problem was that with arm32, we have gpio > > devices created without any of_node or fwnode. So I can't assume > > fwnode will always be present. > > > > Correct, and this one is not even arm32. But it is just reusing a driver > that needs to be supported even on arm32. > > Not sure on how to proceed. As a simple way to check, I added a NULL check > for fwnode building on top of Andy's suggestion[1]. That works. > > Also the driver in question on arm64 FVP model is drivers/mfd/vexpress-sysreg.c > mfd_add_device() in drivers/mfd/mfd-core.c allows addition of devices without > of_node/fwnode. I am sure returning error like[2] will break many platforms > but I just wanted to confirm the root cause and [2] fixes the boot without > NULL check for fwnode in gpiochip_setup_dev(). > > Hope this helps. Thanks for debugging it for me Sudeep. Incorporated into my v3. -Saravana > > -- > Regards, > Sudeep > > [1] > > -->8 > diff --git i/drivers/gpio/gpiolib.c w/drivers/gpio/gpiolib.c > index b23140c6485f..e162f13aa2c9 100644 > --- i/drivers/gpio/gpiolib.c > +++ w/drivers/gpio/gpiolib.c > @@ -577,13 +577,15 @@ static void gpiodevice_release(struct device *dev) > static int gpiochip_setup_dev(struct gpio_device *gdev) > { > int ret; > + struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); > > /* > * If fwnode doesn't belong to another device, it's safe to clear its > * initialized flag. > */ > - if (!gdev->dev.fwnode->dev) > - fwnode_dev_initialized(gdev->dev.fwnode, false); > + if (fwnode && !fwnode->dev) > + fwnode_dev_initialized(fwnode, false); > + > ret = gcdev_register(gdev, gpio_devt); > if (ret) > return ret; > > [2] > > -->8 > > diff --git i/drivers/mfd/mfd-core.c w/drivers/mfd/mfd-core.c > index 16d1861e9682..3b2c4b0e9a2a 100644 > --- i/drivers/mfd/mfd-core.c > +++ w/drivers/mfd/mfd-core.c > @@ -231,9 +231,11 @@ static int mfd_add_device(struct device *parent, int id, > } > } > > - if (!pdev->dev.of_node) > + if (!pdev->dev.of_node) { > pr_warn("%s: Failed to locate of_node [id: %d]\n", > cell->name, platform_id); > + goto fail_alias; > + } > } > > mfd_acpi_add_device(cell, pdev); > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel