linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] rtc: pcf85063: fallback to parent of_node
@ 2021-03-10 21:10 Francois Gervais
  2021-04-16 22:16 ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Francois Gervais @ 2021-03-10 21:10 UTC (permalink / raw)
  To: linux-rtc
  Cc: Alessandro Zummo, Alexandre Belloni, Michael McCormick,
	linux-kernel, Francois Gervais

The rtc device node is always or at the very least can possibly be NULL.

Since v5.12-rc1-dontuse/3c9ea42802a1fbf7ef29660ff8c6e526c58114f6 this
will lead to a NULL pointer dereference.

To fix this we fallback to using the parent node which is the i2c client
node as set by devm_rtc_allocate_device().

Using the i2c client node seems to be what other similar drivers do
e.g. rtc-pcf8563.c.

Signed-off-by: Francois Gervais <fgervais@distech-controls.com>
---
 drivers/rtc/rtc-pcf85063.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index aef6c1ee8bb0..463991c74fdd 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -478,6 +478,7 @@ static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063)
 {
 	struct clk *clk;
 	struct clk_init_data init;
+	struct device_node *node = pcf85063->rtc->dev.of_node;
 
 	init.name = "pcf85063-clkout";
 	init.ops = &pcf85063_clkout_ops;
@@ -486,16 +487,17 @@ static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063)
 	init.num_parents = 0;
 	pcf85063->clkout_hw.init = &init;
 
+	if (node == NULL)
+		node = pcf85063->rtc->dev.parent->of_node;
+
 	/* optional override of the clockname */
-	of_property_read_string(pcf85063->rtc->dev.of_node,
-				"clock-output-names", &init.name);
+	of_property_read_string(node, "clock-output-names", &init.name);
 
 	/* register the clock */
 	clk = devm_clk_register(&pcf85063->rtc->dev, &pcf85063->clkout_hw);
 
 	if (!IS_ERR(clk))
-		of_clk_add_provider(pcf85063->rtc->dev.of_node,
-				    of_clk_src_simple_get, clk);
+		of_clk_add_provider(node, of_clk_src_simple_get, clk);
 
 	return clk;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-24 12:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 21:10 [PATCH 1/1] rtc: pcf85063: fallback to parent of_node Francois Gervais
2021-04-16 22:16 ` Alexandre Belloni
2021-05-22 15:36   ` Marc Kleine-Budde
2021-05-23  8:21     ` Greg Kroah-Hartman
2021-05-23 18:24       ` Marc Kleine-Budde
2021-05-24 12:45         ` Greg Kroah-Hartman

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).