clk: Check that ops of composite clock components exist before calling
authorSean Anderson <seanga2@gmail.com>
Wed, 24 Jun 2020 10:41:07 +0000 (06:41 -0400)
committerAndes <uboot@andestech.com>
Wed, 1 Jul 2020 07:01:21 +0000 (15:01 +0800)
commit5e8317a9faff472e8b83f5760535e9bf40571a8a
tree7c7737a0844418e2dd72cd8a7d14ea83664b2171
parent78ce0bd3acafc51e94157ff99aec3ed82e685ef5
clk: Check that ops of composite clock components exist before calling

clk_composite_ops was shared between all devices in the composite clock
driver.  If one clock had a feature (such as supporting set_parent) which
another clock did not, it could call a null pointer dereference.

This patch does three things
1. It adds null-pointer checks to all composite clock functions.
2. It makes clk_composite_ops const and sets its functions at compile-time.
3. It adds some basic sanity checks to num_parents.

The combined effect of these changes is that any of mux, rate, or gate can
be NULL, and composite clocks will still function normally. Previously, at
least mux had to exist, since clk_composite_get_parent was used to
determine the parent for clk_register.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Acked-by: Lukasz Majewski <lukma@denx.de>
drivers/clk/clk-composite.c