linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rt2x00: call clk_get_rate only if we have a clock
@ 2017-07-08  7:27 Mathias Kresin
  2017-07-08 11:15 ` Jonas Gorski
  2017-07-25 12:44 ` Kalle Valo
  0 siblings, 2 replies; 5+ messages in thread
From: Mathias Kresin @ 2017-07-08  7:27 UTC (permalink / raw)
  To: sgruszka, helmut.schaa, kvalo; +Cc: linux-wireless

If clk_get returns an error, rt2x00dev->clk is set to NULL. In
contrast to the common clock framework provided clk_get_rate(), at
least the ramips and bcm63xx legacy implementation of the clk API
access the rate member of the clk struct without a NULL check. This
results into a kernel panic if we do not have a (SoC) clock.

Call clk_get_rate only if we have a clock to fix the issues. This
approach is similar to what is done in the kernel at various places.
Usually clk_get_rate() is only called if clk_get_rate() doesn't return
an error.

Signed-off-by: Mathias Kresin <dev@kresin.me>
---

Resend, the first mail had the wrong list in cc.

 drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index d11c7b2..2a525b9 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -2059,6 +2059,9 @@ static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
 
 static inline bool rt2800_clk_is_20mhz(struct rt2x00_dev *rt2x00dev)
 {
+	if (!rt2x00dev->clk)
+		return 0;
+
 	return clk_get_rate(rt2x00dev->clk) == 20000000;
 }
 
-- 
2.7.4

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

end of thread, other threads:[~2017-07-25 12:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-08  7:27 [PATCH] rt2x00: call clk_get_rate only if we have a clock Mathias Kresin
2017-07-08 11:15 ` Jonas Gorski
2017-07-08 13:37   ` Mathias Kresin
2017-07-10  6:52     ` Stanislaw Gruszka
2017-07-25 12:44 ` Kalle Valo

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