Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14491868ybl; Mon, 30 Dec 2019 11:05:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwvHxE6Dofjg41EnpCBmnJmQoR/LUreuM0PxL1XWqAwAZcUluRbJ0c/EA0m2gT6uNFfxWfd X-Received: by 2002:a05:6830:12da:: with SMTP id a26mr53615606otq.223.1577732754530; Mon, 30 Dec 2019 11:05:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577732754; cv=none; d=google.com; s=arc-20160816; b=j7+s+cpgyaSMMUwCLt9IiHNuocT0kaR0PySfc5oOWwYDRB7rCBvMGThOGo4i6wBhMh QTCrUbXuLkMzUx3WrwsIyK5iUE7nDyw/QTeqrpfsWOsDO+nTloL4gNmiG6vXlMNpXDit K2OXQkp6QNO3CuxjXEDU1exNo24sJC6LXGlLBWA+34Xoxua6B/OkDYhcORLWxiJ7sqGn 0U+tvN6b7p4GLsBgjSqrwxRqKn4Z0E/Gy5COA/Y5UGwd3LLr0+/m1P5ozG06C5sJS7UI oecE+gJJaV00/ifqP1vZ/GvTE+oRqGoL/7LePGBz+Bh+o4jJKVXO6D8tCq6lupvJ5XoS 9BZg== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DXj4r413+sHKXn+FO4leF9lL3sEBo99lc4odUAlEo/A=; b=fX1dJ58uGEPvuvLpBdyQUPDN/rJMCEFciaDyu+Ciw3IsOiTc01RDWBQ+B1vzRcT+wh OJwtDNs+iz9N5hRmj7MUB9FWmlopcUzOxrFdSLVszWg2V0YMm9smcOeMOfXO/hdS11Or sJkuSG0XW1zhmHsjJQN9BpMqsDAi9jJrU4dncFxtq39q63tuprP07fPpmaJXfxT/r25K FIY4QzAqb3bosAZ+LihHxtcSe3H/C2xm3zUra0wbiNAmhTBOz1QixAQCsKgnwwV9PVbX F6v6/GEih0adPM375xUIqh0lesh8KScQufqV/HeztOrN50ZOFaJNZBYdf3lEgaDbyfFD qmhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VXfAVnfX; 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=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 i12si24599116otk.215.2019.12.30.11.05.41; Mon, 30 Dec 2019 11:05:54 -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 header.i=@kernel.org header.s=default header.b=VXfAVnfX; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727612AbfL3TE5 (ORCPT + 99 others); Mon, 30 Dec 2019 14:04:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:38082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbfL3TE4 (ORCPT ); Mon, 30 Dec 2019 14:04:56 -0500 Received: from mail.kernel.org (unknown [104.132.0.74]) (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 CE5C020658; Mon, 30 Dec 2019 19:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577732696; bh=p8M2OEtkcPThYS4Ece3U5r41flQ/iN5brOD0ybpPheo=; h=From:To:Cc:Subject:Date:From; b=VXfAVnfX0pCF4+EO8/FpwofMi0eLyIWyodRALEdQx6v7TeZNY68sIShz3MXJhkLvd Z7B+pXBb+IGbUV+FfUwrVblf+KMh/SYY0vpB7Uh+oNTKkJlNcwD9ryhU9S4jzK8TaS +CmCwoh7G4Xb/r2RPuki2ehFpGcsjh7Q9uWFEk9s= From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Bjorn Andersson , Niklas Cassel Subject: [PATCH] clk: Use parent node pointer during registration if necessary Date: Mon, 30 Dec 2019 11:04:55 -0800 Message-Id: <20191230190455.141339-1-sboyd@kernel.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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); base-commit: e42617b825f8073569da76dc4510bfa019b1c35a -- Sent by a computer, using git, on the internet