Re: [PATCH 56/61] clk: Prefer IS_ERR_OR_NULL over manual NULL check
On Tue, Mar 10, 2026 at 9:57 PM Philipp Hahn wrote: > > Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL > check. > > Semantich change: Previously the code only printed the warning on error, > but not when the pointer was NULL. Now the warning is printed in both > cases! > > Change found with coccinelle. > > To: Michael Turquette > To: Stephen Boyd > To: Daniel Lezcano > To: Thomas Gleixner > Cc: [email protected] > Cc: [email protected] > Signed-off-by: Philipp Hahn > --- > drivers/clk/clk.c | 4 ++-- > drivers/clocksource/timer-pxa.c | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index > 47093cda9df32223c1120c3710261296027c4cd3..35146e3869a7dd93741d10b7223d4488a9216ed1 > 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -4558,7 +4558,7 @@ void clk_unregister(struct clk *clk) > unsigned long flags; > const struct clk_ops *ops; > > - if (!clk || WARN_ON_ONCE(IS_ERR(clk))) > + if (WARN_ON_ONCE(IS_ERR_OR_NULL(clk))) > return; > > clk_debug_unregister(clk->core); > @@ -4744,7 +4744,7 @@ void __clk_put(struct clk *clk) > { > struct module *owner; > > - if (!clk || WARN_ON_ONCE(IS_ERR(clk))) > + if (WARN_ON_ONCE(IS_ERR_OR_NULL(clk))) clk_get_optional() returns NULL if the clk isn't present. Drivers would just pass this to clk_put(). Your change here would cause this pattern to emit a very big warning. I don't think this change should be landed. ChenYu > return; > > clk_prepare_lock(); > diff --git a/drivers/clocksource/timer-pxa.c b/drivers/clocksource/timer-pxa.c > index > 7ad0e5adb2ffac4125c34710fc67f4b45f30331d..f65fb0b7fc318b766227e5e7a4c0fb08ba11c8f9 > 100644 > --- a/drivers/clocksource/timer-pxa.c > +++ b/drivers/clocksource/timer-pxa.c > @@ -218,7 +218,7 @@ void __init pxa_timer_nodt_init(int irq, void __iomem > *base) > > timer_base = base; > clk = clk_get(NULL, "OSTIMER0"); > - if (clk && !IS_ERR(clk)) { > + if (!IS_ERR_OR_NULL(clk)) { > clk_prepare_enable(clk); > pxa_timer_common_init(irq, clk_get_rate(clk)); > } else { > > -- > 2.43.0 > >
Re: [PATCH 56/61] clk: Prefer IS_ERR_OR_NULL over manual NULL check
On Tue, Mar 10, 2026 at 12:49:22PM +0100, Philipp Hahn wrote: > Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL > check. > > Semantich change: Previously the code only printed the warning on error, Semantic ... > but not when the pointer was NULL. Now the warning is printed in both > cases! > > Change found with coccinelle. > > To: Michael Turquette > To: Stephen Boyd > To: Daniel Lezcano > To: Thomas Gleixner > Cc: [email protected] > Cc: [email protected] > Signed-off-by: Philipp Hahn With the minor typo addressed: Reviewed-by: Brian Masney
[PATCH 56/61] clk: Prefer IS_ERR_OR_NULL over manual NULL check
Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL check. Semantich change: Previously the code only printed the warning on error, but not when the pointer was NULL. Now the warning is printed in both cases! Change found with coccinelle. To: Michael Turquette To: Stephen Boyd To: Daniel Lezcano To: Thomas Gleixner Cc: [email protected] Cc: [email protected] Signed-off-by: Philipp Hahn --- drivers/clk/clk.c | 4 ++-- drivers/clocksource/timer-pxa.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 47093cda9df32223c1120c3710261296027c4cd3..35146e3869a7dd93741d10b7223d4488a9216ed1 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -4558,7 +4558,7 @@ void clk_unregister(struct clk *clk) unsigned long flags; const struct clk_ops *ops; - if (!clk || WARN_ON_ONCE(IS_ERR(clk))) + if (WARN_ON_ONCE(IS_ERR_OR_NULL(clk))) return; clk_debug_unregister(clk->core); @@ -4744,7 +4744,7 @@ void __clk_put(struct clk *clk) { struct module *owner; - if (!clk || WARN_ON_ONCE(IS_ERR(clk))) + if (WARN_ON_ONCE(IS_ERR_OR_NULL(clk))) return; clk_prepare_lock(); diff --git a/drivers/clocksource/timer-pxa.c b/drivers/clocksource/timer-pxa.c index 7ad0e5adb2ffac4125c34710fc67f4b45f30331d..f65fb0b7fc318b766227e5e7a4c0fb08ba11c8f9 100644 --- a/drivers/clocksource/timer-pxa.c +++ b/drivers/clocksource/timer-pxa.c @@ -218,7 +218,7 @@ void __init pxa_timer_nodt_init(int irq, void __iomem *base) timer_base = base; clk = clk_get(NULL, "OSTIMER0"); - if (clk && !IS_ERR(clk)) { + if (!IS_ERR_OR_NULL(clk)) { clk_prepare_enable(clk); pxa_timer_common_init(irq, clk_get_rate(clk)); } else { -- 2.43.0
