[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210423191236.265996-1-tudor.ambarus@microchip.com>
Date: Fri, 23 Apr 2021 22:12:36 +0300
From: Tudor Ambarus <tudor.ambarus@...rochip.com>
To: <mturquette@...libre.com>, <sboyd@...nel.org>, <nsaenz@...nel.org>,
<maxime@...no.tech>, <gregkh@...uxfoundation.org>,
<rafael@...nel.org>, <khilman@...nel.org>,
<ulf.hansson@...aro.org>, <len.brown@...el.com>, <pavel@....cz>,
<robh+dt@...nel.org>, <frowand.list@...il.com>, <maz@...nel.org>,
<tglx@...utronix.de>, <saravanak@...gle.com>,
<geert@...ux-m68k.org>, <nsaenzjulienne@...e.de>,
<linux@...ck-us.net>, <guillaume.tucker@...labora.com>
CC: <linux-clk@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<corbet@....net>, <nicolas.ferre@...rochip.com>,
<claudiu.beznea@...rochip.com>, <linux-doc@...r.kernel.org>,
<linux-pm@...r.kernel.org>, <devicetree@...r.kernel.org>,
<linux-acpi@...r.kernel.org>, <kernel-team@...roid.com>,
<linux-rpi-kernel@...ts.infradead.org>,
Tudor Ambarus <tudor.ambarus@...rochip.com>,
Marek Szyprowski <m.szyprowski@...sung.com>
Subject: [PATCH] clk: Skip clk provider registration when np is NULL
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_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@...sung.com>
Fixes: 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
Signed-off-by: Tudor Ambarus <tudor.ambarus@...rochip.com>
---
This would be the second approach, where we don't return an error when
one calls devm_of_clk_add_hw_provider with a NULL of_node, but instead
we just return 0 and skip the logic in the core and the drivers.
drivers/clk/clk.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e2ec1b745243..5d10da3519ac 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4540,6 +4540,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;
@@ -4579,6 +4582,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;
@@ -4676,6 +4682,9 @@ void of_clk_del_provider(struct device_node *np)
{
struct of_clk_provider *cp;
+ if (!np)
+ return 0;
+
mutex_lock(&of_clk_mutex);
list_for_each_entry(cp, &of_clk_providers, link) {
if (cp->node == np) {
--
2.25.1
Powered by blists - more mailing lists