Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3373570pxb; Mon, 9 Nov 2020 09:28:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+einwxwU63kdzLuQcDsYcyA0RJYWi9ERQ1LhohNdWphzNbybof7zp21ihDcwXEHWjDYlm X-Received: by 2002:a17:906:1e08:: with SMTP id g8mr15765978ejj.358.1604942895014; Mon, 09 Nov 2020 09:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604942895; cv=none; d=google.com; s=arc-20160816; b=E/OzCncHhZBh7r/PHqCKJwQKuEQaXpWZhrxjSh3ZLpvRzPRq2WcJW+VGMh385wjdG/ R8LWVtUX3UD3ANBJqqsulRdDFhuWT1GffrWNY3rFBD4vTCPbu8Zt6DbenPsjM0HMsWN/ PmPZkTlnYERSBeWNkZXq8xWp5I4Z4oU02vF7IbRKlAXPUSBYt7fYWmcpQjc7Iis/bCwe hwSFio2N7Jqoc0wxqpRQYGc50WnN8EtkKKJT0RKv2NkohaSuppytUoT+phIDGQSJ0R60 HCQd5Ml95gPnsEcvgdWnoLyapnk7yRgbmDYpb1r/fa8V6pOWo2F2vKJQS1QBE7MKGopI rOtQ== 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=uijLTzYmG7P4x9XMgO0CIlLqGJR+irUbUXy6Db/eZIc=; b=dFNoIXlQBIU3P8FgocUMvg+gjH320HcaxQuHa2/0e95Nwyu/cTK4scTE4dVcFi2+oa ZoLzL8L0bFPzAs6UKsGYG5u3CoX65UO/Brcp+UhU0kdg7VpG437EOQIawVVqCqqLE+HK 1tOp1E8qGCSXQtDigO+Ez8bNr7MeLi7xPyC0dYlpP2nJ5nJLSa0MI56TRlKJoxAXK9mG Ka+6K34x2yd7wKTB+miI0i+fjwePgquARdZQ0LpXndp1IA5t4DO6zkVuEvW1MQaYFpr+ ayEd5jxdTbV3dHTjfknfrIp1Jq4VRTjdoo+g3QSMCVuj9IdDMqdRy61mXyUmYAlp9qJr +Pkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b0Y20zYr; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si6408339ejb.435.2020.11.09.09.27.51; Mon, 09 Nov 2020 09:28:15 -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=@kernel.org header.s=default header.b=b0Y20zYr; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731726AbgKIRZx (ORCPT + 99 others); Mon, 9 Nov 2020 12:25:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:36638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730450AbgKIRZx (ORCPT ); Mon, 9 Nov 2020 12:25:53 -0500 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0F82F20E65 for ; Mon, 9 Nov 2020 17:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604942752; bh=xNe6oI2+GsLqcIEH7PXY3gTJtPh82o7VvswagmdVVV8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=b0Y20zYr/D+UF0W95loXwvzpJVjddKIRGVkeJWu8G6/tWi1uiEntI2b0qKJawzaId wtJSV02HcGSiY/8Sye7nivPMspDC4OWUJS3g/xYbr+H2DwjYdR/HM0Au2IGcdCnadd cFP35bLjVT8qWlaJAMM84/5M3fEbjTFDfC3Jgfy8= Received: by mail-ot1-f48.google.com with SMTP id n15so9696302otl.8 for ; Mon, 09 Nov 2020 09:25:52 -0800 (PST) X-Gm-Message-State: AOAM5337ITgP57eBm3voG/GR0+6VjfN7E0jx3GfOmCIncZRXuEGEi6QS bywnpp7tcpeM/YDGgke9njcNQzZvRMIES7Gi/Q== X-Received: by 2002:a05:6830:2f8:: with SMTP id r24mr11038612ote.129.1604942751273; Mon, 09 Nov 2020 09:25:51 -0800 (PST) MIME-Version: 1.0 References: <20201106150747.31273-1-broonie@kernel.org> In-Reply-To: From: Rob Herring Date: Mon, 9 Nov 2020 11:25:39 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC] driver core: Ensure DT devices always have fwnode set To: Saravana Kannan Cc: Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Daniel Mentz , LKML , Frank Rowand Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 6, 2020 at 1:09 PM Saravana Kannan wrote: > > +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/ It's fwnode specific code because it's fwnode that needs it... > 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. Perhaps a fwnode call in device_add instead that implements the above and anything else needed for each type of fwnode. It might even be possible with that to get rid of most of of_platform_device_create_pdata() and of_device_add(). IIRC, those were pretty much copies of the core code. That would also be less fragile than having a coccinelle script. Rob