Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17989733ybl; Thu, 2 Jan 2020 16:18:35 -0800 (PST) X-Google-Smtp-Source: APXvYqzs3K7RNJFG9L0qwv48v30IsL7DfnsCTmALDvzv7ACOITzNcpfY2VzeeSIvWcShnJSq8Mjt X-Received: by 2002:a9d:461b:: with SMTP id y27mr103441058ote.280.1578010715557; Thu, 02 Jan 2020 16:18:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578010715; cv=none; d=google.com; s=arc-20160816; b=zqgKLO20ycYHwCmEZNAqhYpS6Q9qrx82o8foNTQaoLASbXpRozEiiEFe7fXoGyxf6O SwW/3VuUUP4uU+iqOv9rMsGn2jm8Kkd5cKlP1kf12te3FlrTAfS1K/iSuqLucR5okXj5 SA7W2yRv89+6UxBXSoDp/O4JS2GbfXXFjL4B7RiHqtVXddSsp96jIJVp6GBuhnFdRrOB sHR5IqB3czuhb6CIu81NJWSlOWVF5j+vExd+pAK0OfCpqXFCOFv6u6BnTDI4La6mS4A9 edzT7Qw6ie+1YNKzaSzPwJVGWqbjvRvM/oTa1gKbPaspgYUrZDMJW5oV7aPwY7OfPAMQ OF2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=cww1rlemj26bNhUf55QD0U0OYjSzwgFpv3Sw4ih5L0s=; b=ZwGbq0CV9Ig7juIugzlPs/Xnz+6rDqlrECKRvaWehWG50TKEA4ItUQAb5YZBc9WVa+ fIlsF1fvXKGUKeOvCRcLzExPIhCVU8gqrZ1uyBLROf7KVYgOc+cMAsv3ZgNHleZawIhg M5sSdbMDMObxPKOglR8db5kfXv3xFLo1RW4Ref3t5hIwii8s0YTf2ftExoFfXqcmMqJ4 gbxvyyQmy+CYqxzA32OVXg4HKcKb9O5geeI1H8sM7Ri3DgFutjAGlPzC5xEB9DR4AANn dpFymdgb77+WGxnDCOGxeFlf26n/veyumL+NmrhBPfk8KPu7UpdCGs4JwDCOjIWBy8WH PfQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@flawful.org header.s=mail header.b=jMwyMSB7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q131si16609013oig.203.2020.01.02.16.18.22; Thu, 02 Jan 2020 16:18:35 -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; dkim=pass (test mode) header.i=@flawful.org header.s=mail header.b=jMwyMSB7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726148AbgACARR (ORCPT + 99 others); Thu, 2 Jan 2020 19:17:17 -0500 Received: from ste-pvt-msa1.bahnhof.se ([213.80.101.70]:35505 "EHLO ste-pvt-msa1.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbgACARQ (ORCPT ); Thu, 2 Jan 2020 19:17:16 -0500 Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 3EFB33F43C; Fri, 3 Jan 2020 01:17:13 +0100 (CET) Authentication-Results: ste-pvt-msa1.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=flawful.org header.i=@flawful.org header.b=jMwyMSB7; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Flag: NO X-Spam-Score: -2.099 X-Spam-Level: X-Spam-Status: No, score=-2.099 tagged_above=-999 required=6.31 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Received: from ste-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (ste-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8N7kFaLmKTmI; Fri, 3 Jan 2020 01:17:12 +0100 (CET) Received: from flawful.org (ua-84-217-220-205.bbcust.telenor.se [84.217.220.205]) (Authenticated sender: mb274189) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id B9E123F41D; Fri, 3 Jan 2020 01:17:11 +0100 (CET) Received: by flawful.org (Postfix, from userid 1001) id B260667D; Fri, 3 Jan 2020 01:17:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flawful.org; s=mail; t=1578010630; bh=cww1rlemj26bNhUf55QD0U0OYjSzwgFpv3Sw4ih5L0s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jMwyMSB7CTvZNiQwtvqVov7mg685304CLerqF2sLJedx5OcW5rNpjk93NczStb9gP dk6ND1hAxtrmi9K01J7CWXycv3f9MEU/5Aj7fowNlPPWyaX2siDc/Zen+xZcbzJh6Y 3pW5dpXYxUhBefGcCsNeAzQ9/YAQbKsDwlt82Nr0= Date: Fri, 3 Jan 2020 01:17:10 +0100 From: Niklas Cassel To: Stephen Boyd Cc: Michael Turquette , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Bjorn Andersson , Niklas Cassel Subject: Re: [PATCH] clk: Use parent node pointer during registration if necessary Message-ID: <20200103001710.indj23ajryzj77bf@flawful.org> References: <20191230190455.141339-1-sboyd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191230190455.141339-1-sboyd@kernel.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 30, 2019 at 11:04:55AM -0800, Stephen Boyd wrote: > Sometimes clk drivers are attached to devices which are children of a > parent device that is connected to a node in DT. This happens when > devices are MFD-ish and the parent device driver mostly registers child > devices to match against drivers placed in their respective subsystem > directories like drivers/clk, drivers/regulator, etc. When the clk > driver calls clk_register() with a device pointer, that struct device > pointer won't have a device_node associated with it because it was > created purely in software as a way to partition logic to a subsystem. > > This causes problems for the way we find parent clks for the clks > registered by these child devices because we look at the registering > device's device_node pointer to lookup 'clocks' and 'clock-names' > properties. Let's use the parent device's device_node pointer if the > registering device doesn't have a device_node but the parent does. This > simplifies clk registration code by avoiding the need to assign some > device_node to the device registering the clk. > > Cc: Bjorn Andersson > Reported-by: Niklas Cassel > Signed-off-by: Stephen Boyd > --- > > I decided to introduce a new function instead of trying to jam it all > in the one line where we assign np. This way the function gets the > true 'np' as an argument all the time. > > drivers/clk/clk.c | 27 +++++++++++++++++++++++++-- > 1 file changed, 25 insertions(+), 2 deletions(-) > > > base-commit: e42617b825f8073569da76dc4510bfa019b1c35a > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index b68e200829f2..a743fffe8e46 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -3719,6 +3719,28 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) > return ERR_PTR(ret); > } > > +/** > + * dev_or_parent_of_node - Get device node of @dev or @dev's parent > + * @dev: Device to get device node of > + * > + * Returns: device node pointer of @dev, or the device node pointer of > + * @dev->parent if dev doesn't have a device node, or NULL if neither > + * @dev or @dev->parent have a device node. > + */ > +static struct device_node *dev_or_parent_of_node(struct device *dev) > +{ > + struct device_node *np; > + > + if (!dev) > + return NULL; > + > + np = dev_of_node(dev); > + if (!np) > + np = dev_of_node(dev->parent); > + > + return np; > +} > + > /** > * clk_register - allocate a new clock, register it and return an opaque cookie > * @dev: device that is registering this clock > @@ -3734,7 +3756,7 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) > */ > struct clk *clk_register(struct device *dev, struct clk_hw *hw) > { > - return __clk_register(dev, dev_of_node(dev), hw); > + return __clk_register(dev, dev_or_parent_of_node(dev), hw); > } > EXPORT_SYMBOL_GPL(clk_register); > > @@ -3750,7 +3772,8 @@ EXPORT_SYMBOL_GPL(clk_register); > */ > int clk_hw_register(struct device *dev, struct clk_hw *hw) > { > - return PTR_ERR_OR_ZERO(__clk_register(dev, dev_of_node(dev), hw)); > + return PTR_ERR_OR_ZERO(__clk_register(dev, dev_or_parent_of_node(dev), > + hw)); > } > EXPORT_SYMBOL_GPL(clk_hw_register); > Reviewed-by: Niklas Cassel