Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp450190imp; Wed, 20 Feb 2019 03:09:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IZqVBhDna3pvOtnE8bD95FdmePIA3A+S9UWcNUwnb1PcAcs/8PTy+bU+3uaeZv0EJx7Wnny X-Received: by 2002:a17:902:8348:: with SMTP id z8mr14490894pln.151.1550660983842; Wed, 20 Feb 2019 03:09:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550660983; cv=none; d=google.com; s=arc-20160816; b=wKNlyh6BOGc/3OI6G2OpQGKCq53TvT2RrHOnsbY5JGbFG+Hwxv7W6ZayilSJuPp0rO icha3UuGZSlsogQD7F9ncbx5AfHG0QHkxIQvhHYhCxp3C/k/6mOYjUjUwAHhq28YMHO9 uYhAUMZ59GWfho7shMiuO7AO2qUXG7E5U2qVNz98H/uP4j/vPXpF6Y6O0Dpwqy3SaKoK 042QSaOQxAz9FMP+ut/TjGEeqArJ0TISDWNhultup01Z7GX0rq9DQopjZFXElXwdxCJi fP8EUF2PepB9ErByBv1HufIzcgKkbL0uR84oTfksA3rfXVjyl+0GNrPTZuS38IyU69CP KEjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=cvdWK0kznZaiGuUN+F6BTd8yrUIe9BzVqnI+eguYkeg=; b=GmmWv3zSQifVlvlHBgDtpb9COZjcVYSqZSbGmTaYDL1nCy7QQ+wDuV1c5u9vpdNRoJ 58qsyZhBF4Gg0Ta05yfjj89UlqyVpDHzXkA17XxhKfJVnBafwb9ipo3Z2HIBWSYxIpdL weFOOUaQLgGselTMM3MP+og7wlf27+FoTF0VdjjAxeDLOyt66+2Jru6hs8I/AGvHigKK 8cN64Q0ym/KY+vNLRjoAvI/CFvwqqaTbem1kjG3PIPTf79WmsUmKC7clsmJ+REkJ8L5V KKhLW9TDK9IZMH92Lmgx7+6m3i5sqLUOlcxVQCKWrUXr/hVUQFv2kOYBgBeR2rGWFt7y mrnw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k21si17995247pgb.514.2019.02.20.03.09.28; Wed, 20 Feb 2019 03:09:43 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727421AbfBTLJB convert rfc822-to-8bit (ORCPT + 99 others); Wed, 20 Feb 2019 06:09:01 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:46490 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726209AbfBTLJB (ORCPT ); Wed, 20 Feb 2019 06:09:01 -0500 Received: by mail-ot1-f65.google.com with SMTP id c18so17888857otl.13 for ; Wed, 20 Feb 2019 03:09:00 -0800 (PST) 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:content-transfer-encoding; bh=J6vZdynoXByekuwiZWrZ2EMtGg+SSi482lXCFI69D+I=; b=l+gLpX8MHVMdrLnkLiJgrvrCCss27O7TxdfnEqq2xOZJ35SzXBgyqGTtw5u0eMyTW4 //MIgTl8PSKOCBjetGGNgATJiXFVJqFDbS8Qv2e8MqgETxCah5PkzE4GWzLA6YdoWis0 4+C2L8/XZYhIB65f8KQryIZHt76V5MfRGugW9BtMB9dBbeTx/BIUkvU55HO2/EQauD1Q tuUT3Rb88F/FB4x3WWoe4HdxYi1oAu1ZZ/agtdNsETBRJQawBLMaGApP453pn9S/mLkM VeQsYq+4mZVHVz1spORXHz8wom3f+CEw1IKMhV6CsnsCrPlNTGbvFnKtAO0Rxde3t0Bg E4yA== X-Gm-Message-State: AHQUAuYR/1y859LQxQsqgonE8QSRMHhzEtpe82anRL065F6Cgoj1Sn8Z mIizO5eIwCekJ7kmWSJxbdfxBDotnekYQ9xa4XQ= X-Received: by 2002:a9d:7547:: with SMTP id b7mr4614489otl.244.1550660940138; Wed, 20 Feb 2019 03:09:00 -0800 (PST) MIME-Version: 1.0 References: <20190216164512.9525-1-mans@mansr.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 20 Feb 2019 12:08:49 +0100 Message-ID: Subject: Re: [PATCH] platform: set of_node in platform_device_register_full() To: =?UTF-8?B?TcOlbnMgUnVsbGfDpXJk?= Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 20, 2019 at 12:02 PM Måns Rullgård wrote: > > "Rafael J. Wysocki" writes: > > > On Wed, Feb 20, 2019 at 11:41 AM Måns Rullgård wrote: > >> > >> "Rafael J. Wysocki" writes: > >> > >> > On Mon, Feb 18, 2019 at 12:10 PM Måns Rullgård wrote: > >> >> > >> >> "Rafael J. Wysocki" writes: > >> >> > >> >> > On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard wrote: > >> >> >> > >> >> >> If the provided fwnode is an OF node, set dev.of_node as well. > >> >> >> > >> >> >> Signed-off-by: Mans Rullgard > >> >> >> --- > >> >> >> drivers/base/platform.c | 1 + > >> >> >> 1 file changed, 1 insertion(+) > >> >> >> > >> >> >> diff --git a/drivers/base/platform.c b/drivers/base/platform.c > >> >> >> index dff82a3c2caa..853a1d0e5845 100644 > >> >> >> --- a/drivers/base/platform.c > >> >> >> +++ b/drivers/base/platform.c > >> >> >> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full( > >> >> >> > >> >> >> pdev->dev.parent = pdevinfo->parent; > >> >> >> pdev->dev.fwnode = pdevinfo->fwnode; > >> >> >> + pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode)); > >> >> > > >> >> > of_node_get() generally does a kobject_get() on the node's kobject, so > >> >> > when is that reference dropped? Or if it doesn't need to be dropped > >> >> > at all, why is this the case? > >> >> > >> >> platform_device_release() calls of_device_node_put(). > >> > > >> > Yes, it does, but this is the reference that's already acquired for > >> > devices added while parsing DT, isn't it? > >> > > >> > Your change adds an extra reference AFAICS. > >> > > >> > Also, why is this patch needed? > >> > >> Some drivers are just shims that create extra "glue" devices with the DT > >> device as parent and have the real driver bind to these. In other > >> cases, the same real driver matches the DT node directly. When a glue > >> device is used, it needs to get a reference to the original DT node in > >> order for the main driver to access properties and child nodes. > >> > >> Right now, my problem is that the suxi-musb driver creates such a glue > >> device for the musb core driver to bind to without setting of_node. > >> This means devices attached to this USB interface don't get associated > >> with DT nodes, if present, the way they do with EHCI. > > > > You really should describe problems that you want to address in patch > > changelogs. This helps a lot to understand the motivation for the > > changes. > > Do you want me to send a new patch with the above explanation in the > commit message? Yes, please. > >> The sunxi-musb driver uses platform_device_register_full(), so this > >> seemed like the easiest way to let it set of_node of the new device. > >> Since this creates a second reference to the same node, of_node_get() > >> is required. > > > > But what about devices that already have of_node set at this point? > > > > Maybe check if of_node is NULL before trying to set it? > > It's a brand new device allocated a few lines above. of_node has to be > null here. Right, sorry for the confusion.