Skip to contentSkip to conversation

make clk_get_rate implementations behavior more consistent

PATCH In review Jonas Gorski 6 participants 20 messages Jul 18, 2017 – Jul 19, 2017

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover make clk_get_rate implementations behavior more consistent

The common clock and several other clock API implementations allow calling clk_get_rate with a NULL pointer. While not specified as expected behavior of the API, device drivers have come to rely on that, causing them to OOPS when run on a platform with a different clock API implementation.

Fix this by making sure all clk_get_rate implementations handle NULL clocks instead of OOPSing.

While some custom implementations even allow ERR_PTR()s, I decided against that as IIRC the usual idea is that errors should be handled and not silently carried over.

Cc adi-buildroot-devel at lists.sourceforge.net
Cc bcm-kernel-feedback-list at broadcom.com
Cc linux-arm-kernel at lists.infradead.org
Cc linux-kernel at vger.kernel.org
Cc linux-m68k at lists.linux-m68k.org
Cc linux-mips at linux-mips.org

Jonas Gorski (9):
ARM: ep93xx: allow NULL clock for clk_get_rate
ARM: mmp: allow NULL clock for clk_get_rate
blackfin: bf609: allow NULL clock for clk_get_rate
m68k: allow NULL clock for clk_get_rate
MIPS: AR7: allow NULL clock for clk_get_rate
MIPS: BCM63XX: allow NULL clock for clk_get_rate
MIPS: Loongson 2F: allow NULL clock for clk_get_rate
MIPS: ralink: allow NULL clock for clk_get_rate
unicore32: allow NULL clock for clk_get_rate

 arch/arm/mach-ep93xx/clock.c           | 3 +++
 arch/arm/mach-mmp/clock.c              | 4 +++-
 arch/blackfin/mach-bf609/clock.c       | 2 +-
 arch/m68k/coldfire/clk.c               | 3 +++
 arch/mips/ar7/clock.c                  | 3 +++
 arch/mips/bcm63xx/clk.c                | 3 +++
 arch/mips/loongson64/lemote-2f/clock.c | 3 +++
 arch/mips/ralink/clk.c                 | 3 +++
 arch/unicore32/kernel/clock.c          | 3 +++
 9 files changed, 25 insertions(+), 2 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/9 ARM: ep93xx: allow NULL clock for clk_get_rate

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 1d81eedb8f6c ("[ARM] 3634/1: ep93xx: initial implementation of the clk_* API")
Cc Hartley Sweeten <[email protected]>
Cc Alexander Sverdlin <[email protected]>
Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linux-kernel at vger.kernel.org
---
 arch/arm/mach-ep93xx/clock.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-ep93xx/clock.c +3 -0
index 39ef3b613912..f0768befafe8 100644
@@ -316,6 +316,9 @@ static unsigned long get_uart_rate(struct clk *clk)
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	if (clk->get_rate)
 		return clk->get_rate(clk);
 
Signature · 1 line
2.11.0
#3 lore raw

PATCH 2/9 ARM: mmp: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 49cbe78637eb ("[ARM] pxa: add base support for Marvell's PXA168 processor line")
Cc Eric Miao <[email protected]>
Cc Haojian Zhuang <[email protected]>
Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linux-kernel at vger.kernel.org
---
 arch/arm/mach-mmp/clock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/mach-mmp/clock.c +3 -1
index 28fe64c6e2f5..bdfb113431ec 100644
@@ -83,7 +83,9 @@ unsigned long clk_get_rate(struct clk *clk)
 {
 	unsigned long rate;
 
-	if (clk->ops->getrate)
+	if (!clk)
+		rate = 0;
+	else if (clk->ops->getrate)
 		rate = clk->ops->getrate(clk);
 	else
 		rate = clk->rate;
Signature · 1 line
2.11.0
#6 lore raw

PATCH 4/9 m68k: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
---
 arch/m68k/coldfire/clk.c | 3 +++
 1 file changed, 3 insertions(+)
arch/m68k/coldfire/clk.c +3 -0
index 1e3c7e9193d1..856069a3196d 100644
@@ -121,6 +121,9 @@ EXPORT_SYMBOL(clk_put);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
Signature · 1 line
2.11.0
#4 lore raw

PATCH 3/9 blackfin: bf609: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 969003152aa9 ("blackfin: bf60x: add clock support")
Cc Steven Miao <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Andrew Morton <[email protected]>
---
 arch/blackfin/mach-bf609/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/blackfin/mach-bf609/clock.c +1 -1
index 392a59b9a504..21a0ec18829f 100644
@@ -109,7 +109,7 @@ EXPORT_SYMBOL(clk_disable);
 unsigned long clk_get_rate(struct clk *clk)
 {
 	unsigned long ret = 0;
-	if (clk->ops && clk->ops->get_rate)
+	if (clk && clk->ops && clk->ops->get_rate)
 		ret = clk->ops->get_rate(clk);
 	return ret;
 }
Signature · 1 line
2.11.0
#7 lore raw

PATCH 4/9 m68k: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
---
 arch/m68k/coldfire/clk.c | 3 +++
 1 file changed, 3 insertions(+)
arch/m68k/coldfire/clk.c +3 -0
index 1e3c7e9193d1..856069a3196d 100644
@@ -121,6 +121,9 @@ EXPORT_SYMBOL(clk_put);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
Signature · 1 line
2.11.0
#13 lore raw

PATCH 5/9 MIPS: AR7: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 780019ddf02f ("MIPS: AR7: Implement clock API")
Cc Ralf Baechle <[email protected]>
Cc Paul Gortmaker <[email protected]>
Cc James Hogan <[email protected]>
---
 arch/mips/ar7/clock.c | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/ar7/clock.c +3 -0
index dda422a0f36c..0137656107a9 100644
@@ -430,6 +430,9 @@ EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
Signature · 1 line
2.11.0
#14 lore raw

PATCH 6/9 MIPS: BCM63XX: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes e7300d04bd08 ("MIPS: BCM63xx: Add support for the Broadcom BCM63xx family of SOCs.")
Cc Ralf Baechle <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc James Hogan <[email protected]>
---
 arch/mips/bcm63xx/clk.c | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/bcm63xx/clk.c +3 -0
index 73626040e4d6..19577f771c1f 100644
@@ -339,6 +339,9 @@ EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 
Signature · 1 line
2.11.0
#16 lore raw

PATCH 7/9 MIPS: Loongson 2F: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter, as some device drivers rely on this.

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes f8ede0f700f5 ("MIPS: Loongson 2F: Add CPU frequency scaling support")
Cc Ralf Baechle <[email protected]>
---
 arch/mips/loongson64/lemote-2f/clock.c | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/loongson64/lemote-2f/clock.c +3 -0
index a78fb657068c..8281334df9c8 100644
@@ -80,6 +80,9 @@ EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return (unsigned long)clk->rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
Signature · 1 line
2.11.0
#17 lore raw

PATCH 8/9 MIPS: ralink: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 3f0a06b0368d ("MIPS: ralink: adds clkdev code")
Cc John Crispin <[email protected]>
Cc Ralf Baechle <[email protected]>
---
 arch/mips/ralink/clk.c | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/ralink/clk.c +3 -0
index eb1c61917eb7..1b7df115eb60 100644
@@ -53,6 +53,9 @@ EXPORT_SYMBOL_GPL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 EXPORT_SYMBOL_GPL(clk_get_rate);
Signature · 1 line
2.11.0
#18 lore raw

PATCH 9/9 unicore32: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 64909882862e ("unicore32 additional architecture files: pm related files")
Cc Guan Xuetao <[email protected]>
---
 arch/unicore32/kernel/clock.c | 3 +++
 1 file changed, 3 insertions(+)
arch/unicore32/kernel/clock.c +3 -0
index b1ca775f6f6e..d867f34fdb74 100644
@@ -92,6 +92,9 @@ EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
Signature · 1 line
2.11.0
maintainer Reviewed-by on the v1 series
#19 lore raw
In reply to Jonas Gorski

Hi Jonas,

Quoted 31 lines · Jonas Gorski

The common clock and several other clock API implementations allow calling clk_get_rate with a NULL pointer. While not specified as expected behavior of the API, device drivers have come to rely on that, causing them to OOPS when run on a platform with a different clock API implementation.

Fix this by making sure all clk_get_rate implementations handle NULL clocks instead of OOPSing.

While some custom implementations even allow ERR_PTR()s, I decided against that as IIRC the usual idea is that errors should be handled and not silently carried over.

Cc adi-buildroot-devel at lists.sourceforge.net
Cc bcm-kernel-feedback-list at broadcom.com
Cc linux-arm-kernel at lists.infradead.org
Cc linux-kernel at vger.kernel.org
Cc linux-m68k at lists.linux-m68k.org
Cc linux-mips at linux-mips.org

Jonas Gorski (9):
ARM: ep93xx: allow NULL clock for clk_get_rate
ARM: mmp: allow NULL clock for clk_get_rate
blackfin: bf609: allow NULL clock for clk_get_rate
m68k: allow NULL clock for clk_get_rate
MIPS: AR7: allow NULL clock for clk_get_rate
MIPS: BCM63XX: allow NULL clock for clk_get_rate
MIPS: Loongson 2F: allow NULL clock for clk_get_rate
MIPS: ralink: allow NULL clock for clk_get_rate
unicore32: allow NULL clock for clk_get_rate

Quoted 10 lines
 arch/arm/mach-ep93xx/clock.c           | 3 +++
 arch/arm/mach-mmp/clock.c              | 4 +++-
 arch/blackfin/mach-bf609/clock.c       | 2 +-
 arch/m68k/coldfire/clk.c               | 3 +++
 arch/mips/ar7/clock.c                  | 3 +++
 arch/mips/bcm63xx/clk.c                | 3 +++
 arch/mips/loongson64/lemote-2f/clock.c | 3 +++
 arch/mips/ralink/clk.c                 | 3 +++
 arch/unicore32/kernel/clock.c          | 3 +++
 9 files changed, 25 insertions(+), 2 deletions(-)

For the whole series:

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer Acked-by on v1 4/9
#8 lore raw

Re: [PATCH 4/9] m68k: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Hi Jonas,

Quoted 6 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>

Do you want me to push this via the m68knommu git tree? Or are you (or someone) taking the series as a whole?

Regards
Greg

Quoted 24 lines
---
  arch/m68k/coldfire/clk.c | 3 +++
  1 file changed, 3 insertions(+)
arch/m68k/coldfire/clk.c +3 -0
index 1e3c7e9193d1..856069a3196d 100644
@@ -121,6 +121,9 @@ EXPORT_SYMBOL(clk_put);
 
  unsigned long clk_get_rate(struct clk *clk)
  {
+	if (!clk)
+		return 0;
+
  	return clk->rate;
  }
  EXPORT_SYMBOL(clk_get_rate);
Reviewed-by on v1 3/9
#5 lore raw

Re: [PATCH 3/9] blackfin: bf609: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

2017-07-18 19:17 GMT+09:00 Jonas Gorski <[email protected]>:

Quoted 7 lines

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes 969003152aa9 ("blackfin: bf60x: add clock support")
Cc Steven Miao <[email protected]>
Cc Masahiro Yamada <[email protected]>

This Cc can be replaced with

Thank you.

Quoted 25 lines
---
 arch/blackfin/mach-bf609/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/blackfin/mach-bf609/clock.c +1 -2
index 392a59b9a504..21a0ec18829f 100644
@@ -109,7 +109,7 @@ EXPORT_SYMBOL(clk_disable);
 unsigned long clk_get_rate(struct clk *clk)
 {
        unsigned long ret = 0;
-       if (clk->ops && clk->ops->get_rate)
+       if (clk && clk->ops && clk->ops->get_rate)
                ret = clk->ops->get_rate(clk);
        return ret;
 }
--

2.11.0

Signature · 2 lines
Best Regards
Masahiro Yamada
Reviewed-by on v1 6/9
#15 lore raw

Re: [PATCH 6/9] MIPS: BCM63XX: allow NULL clock for clk_get_rate

In reply to Jonas Gorski
Quoted 4 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Quoted 9 lines
Fixes e7300d04bd08 ("MIPS: BCM63xx: Add support for the Broadcom BCM63xx family of SOCs.")
Cc Ralf Baechle <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc James Hogan <[email protected]>
Signature · 1 line
Florian
maintainer Acked-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] ARM: ep93xx: allow NULL clock for clk_get_rate

In reply to Jonas Gorski
Quoted 4 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Quoted 8 lines
Fixes 1d81eedb8f6c ("[ARM] 3634/1: ep93xx: initial implementation of the clk_* API")
Cc Hartley Sweeten <[email protected]>
Cc Alexander Sverdlin <[email protected]>
Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linux-kernel at vger.kernel.org
Quoted 17 lines
---
 arch/arm/mach-ep93xx/clock.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-ep93xx/clock.c +3 -0
index 39ef3b613912..f0768befafe8 100644
@@ -316,6 +316,9 @@ static unsigned long get_uart_rate(struct clk *clk)
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	if (clk->get_rate)
 		return clk->get_rate(clk);
#9 lore raw

Re: [PATCH 4/9] m68k: allow NULL clock for clk_get_rate

In reply to Greg Ungerer

Hi Greg,

Quoted 8 lines · Greg Ungerer

Hi Jonas,

Quoted 5 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Quoted 8 lines
Quoted 2 lines
Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>

Do you want me to push this via the m68knommu git tree? Or are you (or someone) taking the series as a whole?

Please take it through your tree. I totally forgot mentioning in the cover letter that I'm just a simple patch submitter and don't have my own tree. Too long ago that I sent a multi-tree patch series last time ... .

Regards
Jonas

#10 lore raw

Re: [PATCH 4/9] m68k: allow NULL clock for clk_get_rate

In reply to Greg Ungerer

Hi Greg,

Quoted 8 lines · Greg Ungerer

Hi Jonas,

Quoted 5 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Quoted 8 lines
Quoted 2 lines
Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>

Do you want me to push this via the m68knommu git tree? Or are you (or someone) taking the series as a whole?

Please take it through your tree. I totally forgot mentioning in the cover letter that I'm just a simple patch submitter and don't have my own tree. Too long ago that I sent a multi-tree patch series last time ... .

Regards
Jonas

maintainer
#11 lore raw

Re: [PATCH 4/9] m68k: allow NULL clock for clk_get_rate

Hi Jonas,

Quoted 15 lines · Jonas Gorski

Hi Greg,

Quoted 12 lines · Greg Ungerer

Hi Jonas,

Quoted 7 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>
Quoted 8 lines
Quoted 4 lines

Do you want me to push this via the m68knommu git tree? Or are you (or someone) taking the series as a whole?

Please take it through your tree. I totally forgot mentioning in the cover letter that I'm just a simple patch submitter and don't have my own tree. Too long ago that I sent a multi-tree patch series last time

No problem. Added to the m68knommu git tree, for-next branch.

Thanks
Greg

maintainer
#12 lore raw

Re: [PATCH 4/9] m68k: allow NULL clock for clk_get_rate

In reply to Jonas Gorski

Hi Jonas,

Quoted 15 lines · Jonas Gorski

Hi Greg,

Quoted 12 lines · Greg Ungerer

Hi Jonas,

Quoted 7 lines · Jonas Gorski

Make the behaviour of clk_get_rate consistent with common clk's clk_get_rate by accepting NULL clocks as parameter. Some device drivers rely on this, and will cause an OOPS otherwise.

Fixes facdf0ed4f59 ("m68knommu: introduce basic clk infrastructure")
Cc Greg Ungerer <[email protected]>
Quoted 8 lines
Quoted 4 lines

Do you want me to push this via the m68knommu git tree? Or are you (or someone) taking the series as a whole?

Please take it through your tree. I totally forgot mentioning in the cover letter that I'm just a simple patch submitter and don't have my own tree. Too long ago that I sent a multi-tree patch series last time

No problem. Added to the m68knommu git tree, for-next branch.

Thanks
Greg