Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1934492ybl; Thu, 29 Aug 2019 00:47:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyObD+I5P9q2AWGMJljVB+H6QosKGZya2K8VSsm/qbmU6JDXcE3f351NYL17jz8BdUryY1B X-Received: by 2002:a63:d741:: with SMTP id w1mr6863239pgi.155.1567064859573; Thu, 29 Aug 2019 00:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567064859; cv=none; d=google.com; s=arc-20160816; b=LNFbvmB6ArF6EJRrrSqOGrekgMi/vt/paCdC1SeaTIq0hKlqlDH32c+jkp3XExXPUi e6hCOsgNBFmxn5Ssak4U0ikSRDjspQ+K/6ZfzJMQD34Rd06pSi4cpo6ZtfhVKj1KP7N9 ptbuPKxTZrIs1UzvDN+xgQmiY5IgZ0K5zUotBeNVoY2Ws2PucO4G95CDPNVJ1deCR1Ms JmF9IGrzBpUS3UAsrQTj2yi7xM8LyFvRMX2jyg5BFKg5c9bLSfLDtMOYyf8WrW3ZzxFP v3blc2qPUPaGGDkTZOgBPc1gXsSl3aPCy6TeGnFUh/15GtCXL9QBHDEeaDqUMiWdJ7NQ 4cjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=2WQfeka9QBJ0u6SuW6w6DrBJqjwEt58/QtmjRSQZxGs=; b=BGIpPhUUdgbB27pkWQZ33ZeZt3GYrnhiTap/YPdxAqpGjIyVuaza71paagEaaRg7rM F0UxPClwDBupn3A/Jal9UxsOHewvFqUfLxRVSgQwnf4WryMHR31hmf1A3EzWz2cE9Cra 6RFIdyCpszKNFwBaVGojGaOpBVp/q1vx7BDl3kyhCSPopKgwDVg6mqtvHvz1szdEv1PX ZPJn+G2wGABJUInhnmSzH/bPajKAkBCyHddYrqYiph6WrSbV5a8qAs6ETWWPgbJ7kHCJ ig1uGiNM6liYg1tKhldbsrT3eIbKHvxIqgCi6G6wcsGk9Q1/Txxl4Oy9+MDYJ+k7b2qn 73uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Uawm/Ct9"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y70si1741269pfg.184.2019.08.29.00.47.24; Thu, 29 Aug 2019 00:47:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Uawm/Ct9"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728006AbfH2Hq1 (ORCPT + 99 others); Thu, 29 Aug 2019 03:46:27 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:52800 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbfH2HqZ (ORCPT ); Thu, 29 Aug 2019 03:46:25 -0400 Received: by mail-pg1-f201.google.com with SMTP id h3so1489167pgc.19 for ; Thu, 29 Aug 2019 00:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=2WQfeka9QBJ0u6SuW6w6DrBJqjwEt58/QtmjRSQZxGs=; b=Uawm/Ct9U0N5DQ5wL+c4cXY7A15ODdjLSpWbtecf7+bVuGrvVT8yhcn0nHza1nYE22 nlfeGgnpm7skSgEmECryCHA+Qkf+BLESDY0MmQ1S05nkBC2F9qXVejgFxY3hdmY01WFP ZBJHWOt2BU0KO1KxZBdrVp+dViuWjW1grr7wNcw8+PvOHYH6O2NhMtIK8HAfYno4cUxv 3+dL8MMGXmiWrBEzFvEAcBKU5KC9riYNb4/pXhvajgW8wWve63HI3peOzrJepZONSDpj 1LDrxdoOMPTFGJo52Ki1v510UgLOMSrNcm4QS8N0lhbixIwWYCkmw+nLbw3oZ8NAcXXF r14A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=2WQfeka9QBJ0u6SuW6w6DrBJqjwEt58/QtmjRSQZxGs=; b=kYF5t2XiwLFVYzY+oFTmd7ffMx8+uP7jgJ0kjQJf67NOPP4ZIvgk5P+IW3qgGnFJoa agnpk/BxhYF+3lL2irK6ria0Sflz8TEmYXQqFcfAecEh1M+eSo3WNW5XdQLFBtx7YdjQ WrKNMxRP5ZvvRZWGB+WWcHPztuDB6tmiX0EUWFKEB4ocCdfySMd3rf4uOJqW64jv5xnd u6deAyR+ArJsPVL5Ab3ggEupMG4pMP3yk0g1I1UZH4/C8azjFyMJ+Bq2vhzOaBuAlXHj npu2z+Nw3YCVXQ4bjZUtaKQtcs6sTrDYNx7WQil+4qubSl09t1OmcSMiP5NNOOcxUWXv u7nw== X-Gm-Message-State: APjAAAWCSbHANp5/SiGOCmydxOc3IZra16g9WUfFD8dE/YySK5S2FOf0 yhTMm3nF7jm7SYTic0ZoA1aORMzq+gsZ9Tg= X-Received: by 2002:a65:52c5:: with SMTP id z5mr7120687pgp.118.1567064784480; Thu, 29 Aug 2019 00:46:24 -0700 (PDT) Date: Thu, 29 Aug 2019 00:46:01 -0700 In-Reply-To: <20190829074603.70424-1-saravanak@google.com> Message-Id: <20190829074603.70424-6-saravanak@google.com> Mime-Version: 1.0 References: <20190829074603.70424-1-saravanak@google.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog Subject: [PATCH v10 5/7] of: property: Create device links for all child-supplier depencencies From: Saravana Kannan To: Rob Herring , Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , Jonathan Corbet , Len Brown Cc: Saravana Kannan , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-acpi@vger.kernel.org, clang-built-linux@googlegroups.com, David Collins , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A parent device can have child devices that it adds when it probes. But this probing of the parent device can happen way after kernel init is done -- for example, when the parent device's driver is loaded as a module. In such cases, if the child devices depend on a supplier in the system, we need to make sure the supplier gets the sync_state() callback only after these child devices are added and probed. To achieve this, when creating device links for a device by looking at its DT node, don't just look at DT references at the top node level. Look at DT references in all the descendant nodes too and create device links from the ancestor device to all these supplier devices. This way, when the parent device probes and adds child devices, the child devices can then create their own device links to the suppliers and further delay the supplier's sync_state() callback to after the child devices are probed. Example: In this illustration, -> denotes DT references and indentation represents child status. Device node A Device node B -> D Device node C -> B, D Device node D Assume all these devices have their drivers loaded as modules. Without this patch, this is the sequence of events: 1. D is added. 2. A is added. 3. Device D probes. 4. Device D gets its sync_state() callback. 5. Device B and C might malfunction because their resources got altered/turned off before they can make active requests for them. With this patch, this is the sequence of events: 1. D is added. 2. A is added and creates device links to D. 3. Device link from A to B is not added because A is a parent of B. 4. Device D probes. 5. Device D does not get it's sync_state() callback because consumer A hasn't probed yet. 5. Device A probes. 5. a. Devices B and C are added. 5. b. Device links from B and C to D are added. 5. c. Device A's probe completes. 6. Device D does not get it's sync_state() callback because consumer A has probed but consumers B and C haven't probed yet. 7. Device B and C probe. 8. Device D gets it's sync_state() callback because all its consumers have probed. 9. None of the devices malfunction. Signed-off-by: Saravana Kannan --- drivers/of/property.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index 82052172f508..420c2d428184 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1207,6 +1207,10 @@ static int __of_link_to_suppliers(struct device *dev, if (of_link_property(dev, con_np, p->name)) ret = -EAGAIN; + for_each_child_of_node(con_np, child) + if (__of_link_to_suppliers(dev, child)) + ret = -EAGAIN; + return ret; } -- 2.23.0.187.g17f5b7556c-goog