From patchwork Thu Aug 6 14:11:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6959531 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7D90E9F38B for ; Thu, 6 Aug 2015 14:21:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 991482066B for ; Thu, 6 Aug 2015 14:21:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4062A20675 for ; Thu, 6 Aug 2015 14:21:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZNM0o-0002v0-E3; Thu, 06 Aug 2015 14:19:14 +0000 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZNM0l-0002pM-HW for linux-arm-kernel@lists.infradead.org; Thu, 06 Aug 2015 14:19:12 +0000 Received: by wijp15 with SMTP id p15so24626243wij.0 for ; Thu, 06 Aug 2015 07:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7oGQSr2lJOp9pjZRXzU2qqFuoRPcmOV4nD9eP4A+1II=; b=avGDKM8z3jTm/WqKXCvJkfMqL4vkHCIck1wuIT+GR7OZq75zj7hRI9OOzIZeOM2mui Kzkj3tyV9MXutFBtghHs+51b6DiWsZ8f22hjMscMtrrBSqxLa2yTYecnHY3aqC5Fjrx0 0yn3lEy0pljVZnOs6VaU0rga6gxOrGWnT3c2xfB8E+yeFn1Nttf4bkIBeBKbT4nspTwM Bry8QpXG8kv+CtbU7L5RllhUjMh2TkmwyLoVtJIxRWJGwE/GREH0gfSt8Z/J/GYDwaXj 73LhySTkEHCR8MsicNDNTwCBeDAs/ElrX60tekIeZJ+75c2hN65RTNM/SnjPrKGKVY5H 0JVQ== X-Received: by 10.194.122.200 with SMTP id lu8mr3615887wjb.83.1438870729773; Thu, 06 Aug 2015 07:18:49 -0700 (PDT) Received: from cizrna.lan ([109.72.12.154]) by smtp.gmail.com with ESMTPSA id z5sm9727282wjr.42.2015.08.06.07.18.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Aug 2015 07:18:49 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v3 01/18] platform: delay OF device-driver matches until late_initcall Date: Thu, 6 Aug 2015 16:11:38 +0200 Message-Id: <1438870315-18689-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1438870315-18689-1-git-send-email-tomeu.vizoso@collabora.com> References: <1438870315-18689-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150806_071911_747837_2E175D72 X-CRM114-Status: GOOD ( 15.08 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Rob Herring , Javier Martinez Canillas , Mark Brown , Thierry Reding , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Delay matches of platform devices with OF nodes until late_initcall, when we are sure that all built-in drivers have been registered already. This is needed to prevent deferred probes because of some drivers not having registered yet. The reason why only platform devices are delayed is that some other devices are expected to be probed earlier than late_initcall, for example, the system PNP driver needs to probe its devices in fs_initcall. Additionally, only platform devices with OF nodes are delayed because some machines may depend on oter platform devices being registered at specific times. Signed-off-by: Tomeu Vizoso --- Changes in v3: - Only delay platform devices with OF nodes Changes in v2: - Move delay to platform.c drivers/base/platform.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 063f0ab15259..0848ece2bf9d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -33,6 +33,8 @@ /* For automatically allocated device IDs */ static DEFINE_IDA(platform_devid_ida); +static bool enable_matches; + struct device platform_bus = { .init_name = "platform", }; @@ -839,6 +841,15 @@ static int platform_match(struct device *dev, struct device_driver *drv) struct platform_device *pdev = to_platform_device(dev); struct platform_driver *pdrv = to_platform_driver(drv); + /* + * Delay matches of OF platform devices until late_initcall, when we + * are sure that all built-in drivers have been registered already. + * This is needed to prevent deferred probes because of some drivers + * not having registered yet. + */ + if (dev->of_node && !enable_matches) + return 0; + /* When driver_override is set, only bind to the matching driver */ if (pdev->driver_override) return !strcmp(pdev->driver_override, drv->name); @@ -859,6 +870,24 @@ static int platform_match(struct device *dev, struct device_driver *drv) return (strcmp(pdev->name, drv->name) == 0); } +static int __probe_device(struct device *dev, void *data) +{ + if (dev->of_node) + device_initial_probe(dev); + + return 0; +} + +static int probe_delayed_matches_initcall(void) +{ + enable_matches = true; + + bus_for_each_dev(&platform_bus_type, NULL, NULL, __probe_device); + + return 0; +} +late_initcall(probe_delayed_matches_initcall); + #ifdef CONFIG_PM_SLEEP static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)