linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tudor Ambarus <tudor.ambarus@microchip.com>
To: <gregkh@linuxfoundation.org>, <rafael@kernel.org>,
	<mturquette@baylibre.com>, <sboyd@kernel.org>,
	<nsaenz@kernel.org>, <maxime@cerno.tech>, <khilman@kernel.org>,
	<ulf.hansson@linaro.org>, <len.brown@intel.com>, <pavel@ucw.cz>,
	<robh+dt@kernel.org>, <frowand.list@gmail.com>, <maz@kernel.org>,
	<tglx@linutronix.de>, <saravanak@google.com>,
	<geert@linux-m68k.org>, <nsaenzjulienne@suse.de>,
	<linux@roeck-us.net>, <guillaume.tucker@collabora.com>
Cc: <linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<corbet@lwn.net>, <nicolas.ferre@microchip.com>,
	<claudiu.beznea@microchip.com>, <linux-doc@vger.kernel.org>,
	<linux-pm@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-acpi@vger.kernel.org>, <kernel-team@android.com>,
	<linux-rpi-kernel@lists.infradead.org>,
	Tudor Ambarus <tudor.ambarus@microchip.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: [PATCH v2] clk: Skip clk provider registration when np is NULL
Date: Mon, 26 Apr 2021 09:56:18 +0300	[thread overview]
Message-ID: <20210426065618.588144-1-tudor.ambarus@microchip.com> (raw)

commit 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
revealed that clk/bcm/clk-raspberrypi.c driver calls
devm_of_clk_add_hw_provider(), with a NULL dev->of_node, which resulted in a
NULL pointer dereference in of_clk_add_hw_provider() when calling
fwnode_dev_initialized().

Returning 0 is reducing the if conditions in driver code and is being
consistent with the CONFIG_OF=n inline stub that returns 0 when CONFIG_OF
is disabled. The downside is that drivers will maybe register clkdev lookups
when they don't need to and waste some memory.

Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
Fixes: 3c9ea42802a1 ("clk: Mark fwnodes when their clock provider is added/removed")
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
v2:
- s/return 0;/return; in void of_clk_del_provider()
- add second fixes tag and Stephen's R-b tag
The opinions on whether to return an error or zero were split. Returning 0
and skipping the logic was considered safer as we don't know for sure if
other drivers are affected. See:
https://lore.kernel.org/lkml/d24bebc5-0f78-021f-293f-e58defa32531@samsung.com/
https://lore.kernel.org/lkml/20210423171335.262316-1-tudor.ambarus@microchip.com/

 drivers/clk/clk.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index a3b30f7de2ef..b47460b40d14 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4552,6 +4552,9 @@ int of_clk_add_provider(struct device_node *np,
 	struct of_clk_provider *cp;
 	int ret;
 
+	if (!np)
+		return 0;
+
 	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
 	if (!cp)
 		return -ENOMEM;
@@ -4591,6 +4594,9 @@ int of_clk_add_hw_provider(struct device_node *np,
 	struct of_clk_provider *cp;
 	int ret;
 
+	if (!np)
+		return 0;
+
 	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
 	if (!cp)
 		return -ENOMEM;
@@ -4688,6 +4694,9 @@ void of_clk_del_provider(struct device_node *np)
 {
 	struct of_clk_provider *cp;
 
+	if (!np)
+		return;
+
 	mutex_lock(&of_clk_mutex);
 	list_for_each_entry(cp, &of_clk_providers, link) {
 		if (cp->node == np) {
-- 
2.25.1


             reply	other threads:[~2021-04-26  6:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26  6:56 Tudor Ambarus [this message]
2021-04-26 18:17 ` Saravana Kannan
2021-04-27 14:57 ` nicolas saenz julienne
2021-05-10 19:36 ` Guenter Roeck
2021-05-11  7:11   ` Greg KH
2021-05-10 20:20 ` Nathan Chancellor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210426065618.588144-1-tudor.ambarus@microchip.com \
    --to=tudor.ambarus@microchip.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=guillaume.tucker@collabora.com \
    --cc=kernel-team@android.com \
    --cc=khilman@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux@roeck-us.net \
    --cc=m.szyprowski@samsung.com \
    --cc=maxime@cerno.tech \
    --cc=maz@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=nsaenz@kernel.org \
    --cc=nsaenzjulienne@suse.de \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=saravanak@google.com \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=ulf.hansson@linaro.org \
    --subject='Re: [PATCH v2] clk: Skip clk provider registration when np is NULL' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).