Skip to contentSkip to conversation

clk: at91: clk-sam9x60-pll: re-factor to support plls with multiple outputs

bug report Dan Carpenter 1 participant 1 message Feb 27, 2023 Common clk

lore
Share & tools
lore
#0 lore raw

Hello Claudiu Beznea,

The patch 43b1bb4a9b3e: "clk: at91: clk-sam9x60-pll: re-factor to support plls with multiple outputs" from Jul 22, 2020, leads to the following Smatch static checker warning:

	drivers/clk/at91/clk-sam9x60-pll.c:672 sam9x60_clk_register_frac_pll()
	warn: passing zero to 'ERR_PTR'

drivers/clk/at91/clk-sam9x60-pll.c

    663                 parent_rate = clk_hw_get_rate(parent_hw);
    664                 if (!parent_rate) {
    665                         hw = ERR_PTR(-EINVAL);
    666                         goto free;
    667                 }
    668 
    669                 ret = sam9x60_frac_pll_compute_mul_frac(&frac->core, FCORE_MIN,
    670                                                         parent_rate, true);
    671                 if (ret <= 0) {
                            ^^^^^^^^
--> 672                         hw = ERR_PTR(ret);
                                ^^^^^^^^^^^^^^^^^

ret can't be zero. I don't know how this is called, but my guess is that if "ret" were zero then "hw" would be NULL and that results in a NULL dereference in the caller.

    673                         goto free;
    674                 }
    675         }
    676         spin_unlock_irqrestore(frac->core.lock, irqflags);
    677 
    678         hw = &frac->core.hw;
    679         ret = clk_hw_register(NULL, hw);
    680         if (ret) {
    681                 kfree(frac);
    682                 hw = ERR_PTR(ret);
    683         }
    684 
    685         return hw;
    686 
    687 free:
    688         spin_unlock_irqrestore(frac->core.lock, irqflags);
    689         kfree(frac);
    690         return hw;
    691 }

regards,
dan carpenter