Since commit 33f016b23a21 ("dpll: fix NULL deref in dpll_device_ops() during teardown race"), dpll_pin_register() accepts a DPLL without registrations unless the pin has measured_freq_get, and dpll_pin_on_pin_register() registers a pin with the DPLLs of the parent pin without a check. The drivers register a DPLL before its pins. Reject a DPLL that is not registered in dpll_pin_register() before its ops are requested, and a parent pin with such a DPLL in dpll_pin_on_pin_register(), and document the order. The pin paths keep the tolerance for a DPLL without registrations from that commit. On E810, ice registers the recovered clock pin of a PF without the CGU under the input pins of the PF with the CGU, and so with its DPLLs. The pin stays registered with them when that PF goes first. Signed-off-by: Ivan Vecera --- Documentation/driver-api/dpll.rst | 2 ++ drivers/dpll/dpll_core.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Documentation/driver-api/dpll.rst b/Documentation/driver-api/dpll.rst index bc34fc83882fac..75ebed0bb95e96 100644 --- a/Documentation/driver-api/dpll.rst +++ b/Documentation/driver-api/dpll.rst @@ -634,6 +634,8 @@ of pin callbacks, and private data pointer for calling them: - dpll_pin_register() - register pin with a dpll device, - dpll_pin_on_pin_register() - register pin with another MUX type pin. +A dpll device is registered before its pins. + Notifications of adding or removing dpll devices are created within subsystem itself. Notifications about registering/deregistering pins are also invoked by diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index e199342652d163..af61c4882c2b6f 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -925,7 +925,7 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, * @priv: pointer to private information of owner * * The @dpll and the @pin must have the same owner, they must be created with - * the same module and clock_id. + * the same module and clock_id. The @dpll must be registered. * * Context: Acquires a lock (dpll_lock) * Return: @@ -951,9 +951,13 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, mutex_lock(&dpll_lock); + if (ASSERT_DPLL_REGISTERED(dpll)) { + ret = -EINVAL; + goto out_unlock; + } dev_ops = dpll_device_ops(dpll); if (WARN_ON(ops->measured_freq_get && - (!dev_ops || !dev_ops->freq_monitor_get || + (!dev_ops->freq_monitor_get || !dev_ops->freq_monitor_set))) { ret = -EINVAL; goto out_unlock; @@ -1039,7 +1043,8 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister); * Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. * The @parent and the @pin must have the same owner, they must be created - * with the same module and clock_id. + * with the same module and clock_id. The dpll devices of the @parent must + * be registered. * * Context: Acquires a lock (dpll_lock) * Return: @@ -1073,7 +1078,11 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, if (ret) goto unlock; xa_for_each(&parent->dpll_refs, i, ref) { - ret = __dpll_pin_register(ref->dpll, pin, ops, priv, parent); + if (ASSERT_DPLL_REGISTERED(ref->dpll)) + ret = -EINVAL; + else + ret = __dpll_pin_register(ref->dpll, pin, ops, priv, + parent); if (ret) { stop = i; goto dpll_unregister; -- 2.56.1