Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1499486pxb; Fri, 6 Nov 2020 11:11:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyXGHmwGa31zFdgNR7VKrcDl3sIELnf78bgBbhnqgXe+ZPao/IHM6XFgD26Yh2yaE0iLBs X-Received: by 2002:a17:906:1989:: with SMTP id g9mr3360338ejd.62.1604689899087; Fri, 06 Nov 2020 11:11:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604689899; cv=none; d=google.com; s=arc-20160816; b=l34qkQp3V7Ct12XkCSTssii5mjswRQZ5GZfwxu0W1mHF15AUYaGlMiH0iVzonWYjto G/mTSecmasWk/x6M57zK193gNgcDvlYSOBYu7SpZPcCvmKk6EZy59VbM/WXzfJCjoh3n qlVPKVKqrs8Un6ZWdwMx2c9ToStIUxA0YBz4zjcIjKS111D4CDhwsKYP/0IhgPlUXzAH z0HAcxxjQ3mw/smvXI50Bdu67uO/IaJmLNJdddMqVuT5z6Q85yhzhfVb/Bn+0LqGU3xT zE40YvNeVin3ZqINleZfKPNf5fBElWJF9vN0J/onLKxxPwavH1auxMqBSmYCJklpWQ/I ketw== 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=WMdG6BPnDo6XPbXbEsnKscK3WeJAWiKsTI6QrLTod9A=; b=dlZzsAeNbTY2DhDj+1wk1cD1y9TVNT+iBe8kKtq84DymtNrFjqDDdXVfy4O4vFXt16 YP2JGRg62qqYpcThUQDX7sVJk+PvjemlYx+XiXEwNX8vcHqy8ZEd0fmSA9Pue3Y3lrvV HRllkXoZMo/bxGWnydz3FiGAqn/JTTs80P9SYr2wCkEQpl1rwu/sGmNCdr9cuErdXXe8 iUuQPXLxYy9jINHhgCyL7qjWaRMmGH+2JyzXlYWYnV35V1ie5ScuXOv2biMHeYhdexHh dTWUg7NOhbrH/otoYYxDet9K8X4RDWWbJPUcanEbPSY7S45osQiJ4uKoZ5pIGI/9g3s+ NRWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="X/TJWDXB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a13si1673282edq.317.2020.11.06.11.11.15; Fri, 06 Nov 2020 11:11:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="X/TJWDXB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728134AbgKFTJz (ORCPT + 99 others); Fri, 6 Nov 2020 14:09:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727985AbgKFTJy (ORCPT ); Fri, 6 Nov 2020 14:09:54 -0500 Received: from mail-yb1-xb41.google.com (mail-yb1-xb41.google.com [IPv6:2607:f8b0:4864:20::b41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7ACC0613D2 for ; Fri, 6 Nov 2020 11:09:54 -0800 (PST) Received: by mail-yb1-xb41.google.com with SMTP id s8so2032248yba.13 for ; Fri, 06 Nov 2020 11:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WMdG6BPnDo6XPbXbEsnKscK3WeJAWiKsTI6QrLTod9A=; b=X/TJWDXBEYcOALQLiBtbYBjoIu64gTaNXTHO7zCrQCIDudKDcTCd2+5xoK+NqjLKdM 8JqudzVLhv+fcwFrS6yxooI09utAw/AudCW+nTXYRkHDB37AKrUrCgKv7sJTRvXeQfS0 mQXOVyjsgcrG6WCZlXI+dN1z1LhOMJRlgQhgC9CaWv0TAKmaPt8fAUXbLFjhVMgsokiO D7uqZYRxOZJm1CQTbkTarrdzMk/O3gZSJyhaf9sgFcLUP2+RomLHaF8Drr2mL2FW6wcG fCW2y5H+8IywC+kUWkxreYy0E1IPH+noc4ld+7Nc8F28xeGSOdSJIhV6Zso8l/VYvTjI VgHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WMdG6BPnDo6XPbXbEsnKscK3WeJAWiKsTI6QrLTod9A=; b=CwW/UESxqFaUqjkZMdODMimOgdoDkHHRsonWNIoowf2DfR292CW6nRRNooiPoafVmi i31IJEy3TTFV2Ld2HV0MySRegHZ9Xc1ZAU3vpH2yeS3+zt4OTzs4fymkzq+cDZRXaBXS JvHcqo+YfkkLVa+ZipjuUF/F5TfFbdELtpqo3dsf1jJzfA6APR94SUF3J1aKnRBjPeKL Gd3Pspj+5rNg7fg/cIvdrttEqESy3AlzLcgBgW6612lZ2Asa0OcSD9va+8UUAwbgE2No Bc6SvsuMTB24f0JdBHshWXPeI64H7CiHhYbobXFXDMH5xMPAkkD5Pl12HYqrL9nMq/s4 73Jg== X-Gm-Message-State: AOAM531sF3UkUvm7TLnZ+5JFKNRmcdpMZCoNhrqnBSo1U39vDi9VDD50 YaD1OfZiUAuKkn0aypHsq0QfCdvTUHZ4I00XTsf/dw== X-Received: by 2002:a25:f817:: with SMTP id u23mr5025809ybd.466.1604689793394; Fri, 06 Nov 2020 11:09:53 -0800 (PST) MIME-Version: 1.0 References: <20201106150747.31273-1-broonie@kernel.org> In-Reply-To: <20201106150747.31273-1-broonie@kernel.org> From: Saravana Kannan Date: Fri, 6 Nov 2020 11:09:17 -0800 Message-ID: Subject: Re: [PATCH RFC] driver core: Ensure DT devices always have fwnode set To: Mark Brown Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Daniel Mentz , LKML , Rob Herring , Frank Rowand Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Rob and Frank On Fri, Nov 6, 2020 at 7:09 AM Mark Brown wrote: > > Currently the fwnode API and things that rely on it like fw_devlink will > not reliably work for devices created from DT since each subsystem that > creates devices must individually set dev->fwnode in addition to setting > dev->of_node, currently a number of subsystems don't do so. Ensure that > this can't get missed by setting fwnode from of_node if it's not > previously been set by the subsystem. > > Reported-by: Saravana Kannan > Signed-off-by: Mark Brown > --- > > *Very* minimally tested. > > drivers/base/core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index d661ada1518f..658626bafd76 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -2864,6 +2864,10 @@ int device_add(struct device *dev) > if (parent && (dev_to_node(dev) == NUMA_NO_NODE)) > set_dev_node(dev, dev_to_node(parent)); > > + /* ensure that fwnode is set up */ > + if (IS_ENABLED(CONFIG_OF) && dev->of_node && !dev->fwnode) > + dev->fwnode = of_fwnode_handle(dev->of_node); > + I don't think we should add more CONFIG_OF specific code in drivers/base/ If you want to do this in "one common place", then I think the way to do this is have include/linux/of.h provide something like: void of_set_device_of_node(dev, of_node) { dev->of_node = of_node; dev->fw_node = &of_node->fwnode; /* bunch of other housekeeping like setting OF_POPULATED and doing proper of_node_get() */ // Passing NULL for of_node could undo all the above for dev->of_node. } And all the subsystems that create their own device from an of_node should use of_set_device_of_node() to set the device's of_node. That way, all this is done in a consistent manner across subsystems and avoid all of the of_get/put() and OF_POPULATED set/clear strewn all over the subsystems. For example a bunch of subsystems don't do of_get()/of_put() correctly when they det a device's of_node (I sent patches as I found them). -Saravana