Skip to contentSkip to conversation

m68k: let clk_enable() return immediately if clk is NULL

PATCH In review Defang Bo 3 participants 3 messages Dec 28, 2020 – Jan 26, 2021

Subsystems (2)
lore
Share & tools
lore

Defang Bo

author
#0 lore raw

PATCH 1/1 m68k: let clk_enable() return immediately if clk is NULL

Similar to commit<742859adc721>("m68k: let clk_disable() return immediately if clk is NULL"). there should be a check for clk to prevent NULL pointer dereference.

---
 arch/m68k/coldfire/clk.c | 3 +++
 1 file changed, 3 insertions(+)
arch/m68k/coldfire/clk.c +3 -0
index 7bc666e..6decd11 100644
@@ -90,6 +90,9 @@ EXPORT_SYMBOL(clk_get);
 int clk_enable(struct clk *clk)
 {
 	unsigned long flags;
+	if (!clk)
+		return -EINVAL;
+
 	spin_lock_irqsave(&clk_lock, flags);
 	if ((clk->enabled++ == 0) && clk->clk_ops)
 		clk->clk_ops->enable(clk);
Signature · 1 line
2.7.4
#1 lore raw

Hi Defang,

Quoted 4 lines · Defang Bo

Similar to commit<742859adc721>("m68k: let clk_disable() return immediately if clk is NULL"). there should be a check for clk to prevent NULL pointer dereference.

Thanks for your patch!

arch/m68k/coldfire/clk.c EXPORT_SYMBOL(clk_get); · line 92

Quoted 6 lines
arch/m68k/coldfire/clk.c +0 -0
@@ -90,6 +90,9 @@ EXPORT_SYMBOL(clk_get);
 int clk_enable(struct clk *clk)
 {
        unsigned long flags;

Please keep the blank line between variable declarations and statements (no complaint from scripts/checkpatch.pl? See Documentation/process/submitting-patches.rst
).

arch/m68k/coldfire/clk.c EXPORT_SYMBOL(clk_get); · line 98

Quoted 6 lines
arch/m68k/coldfire/clk.c +3 -0
+       if (!clk)
+               return -EINVAL;
+
        spin_lock_irqsave(&clk_lock, flags);
        if ((clk->enabled++ == 0) && clk->clk_ops)
                clk->clk_ops->enable(clk);

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#2 lore raw
In reply to Defang Bo

Hi Defang,

Quoted 4 lines · Defang Bo

Similar to commit<742859adc721>("m68k: let clk_disable() return immediately if clk is NULL"). there should be a check for clk to prevent NULL pointer dereference.

I have applied this to the m68knommu git tree, for-next branch - with blank line added as per Geert's suggestion.

Regards
Greg

Quoted 19 lines
---
  arch/m68k/coldfire/clk.c | 3 +++
  1 file changed, 3 insertions(+)
arch/m68k/coldfire/clk.c +3 -0
index 7bc666e..6decd11 100644
@@ -90,6 +90,9 @@ EXPORT_SYMBOL(clk_get);
  int clk_enable(struct clk *clk)
  {
  	unsigned long flags;
+	if (!clk)
+		return -EINVAL;
+
  	spin_lock_irqsave(&clk_lock, flags);
  	if ((clk->enabled++ == 0) && clk->clk_ops)
  		clk->clk_ops->enable(clk);