dpll: zl3073x: various fixes
Subsystems (4)
Ivan Vecera
maintainercover dpll: zl3073x: various fixes
Three fixes for the zl3073x DPLL driver.
Patch 1 exports __dpll_device_change_ntf() for use by drivers that need to send device change notifications from within callbacks already running under dpll_lock.
Patch 2 replaces the change_work workqueue mechanism with direct calls to __dpll_device_change_ntf(), eliminating a race condition where the work handler could dereference a freed dpll_dev pointer during device teardown.
Patch 3 moves the freq_monitor flag from per-DPLL to per-device scope to match the hardware behavior where frequency measurement registers are shared across all DPLL channels.
Ivan Vecera (3):
dpll: export __dpll_device_change_ntf() for use under dpll_lock
dpll: zl3073x: use __dpll_device_change_ntf() and remove change_work
dpll: zl3073x: make frequency monitor a per-device attribute
drivers/dpll/dpll_netlink.c | 13 +++++++-- drivers/dpll/zl3073x/core.c | 19 ++++++------- drivers/dpll/zl3073x/core.h | 4 ++- drivers/dpll/zl3073x/dpll.c | 55 ++++++++++++++++--------------------- drivers/dpll/zl3073x/dpll.h | 4 --- include/linux/dpll.h | 1 + 6 files changed, 46 insertions(+), 50 deletions(-)
Signature · 1 line
2.53.0
Ivan Vecera
maintainerPATCH 1/3 dpll: export __dpll_device_change_ntf() for use under dpll_lock
Export __dpll_device_change_ntf() so that drivers can send device change notifications from within device callbacks, which are already called under dpll_lock. Using dpll_device_change_ntf() in that context would deadlock.
Add lockdep_assert_held() to catch misuse without the lock held.
--- drivers/dpll/dpll_netlink.c | 13 +++++++++++-- include/linux/dpll.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/dpll/dpll_netlink.c +11 -2
@@ -829,12 +829,21 @@ int dpll_device_delete_ntf(struct dpll_device *dpll)return dpll_device_event_send (DPLL_CMD_DEVICE_DELETE_NTF , dpll); } -static int -__dpll_device_change_ntf (struct dpll_device *dpll) +/** +* __dpll_device_change_ntf - notify that the dpll device has been changed +* @dpll: registered dpll pointer +* +* Context: caller must hold dpll_lock. Suitable for use inside device +* callbacks which are already invoked under dpll_lock. +* Return: 0 if succeeds, error code otherwise. +*/ +int __dpll_device_change_ntf (struct dpll_device *dpll) { +lockdep_assert_held (&dpll_lock);dpll_device_notify (dpll,DPLL_DEVICE_CHANGED );return dpll_device_event_send (DPLL_CMD_DEVICE_CHANGE_NTF , dpll); } +EXPORT_SYMBOL_GPL (__dpll_device_change_ntf);/** * dpll_device_change_ntf - notify that the dpll device has been changed
include/linux/dpll.h +1 -0
@@ -284,6 +284,7 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin,int dpll_pin_ref_sync_pair_add (struct dpll_pin *pin,struct dpll_pin *ref_sync_pin); +int __dpll_device_change_ntf (struct dpll_device *dpll);int dpll_device_change_ntf (struct dpll_device *dpll);int __dpll_pin_change_ntf (struct dpll_pin *pin);
Signature · 1 line
2.53.0
Re: [PATCH net 1/3] dpll: export __dpll_device_change_ntf() for use under dpll_lock
Quoted 8 lines · Tue, May 26, 2026 at 09:45:23AM +0200, [email protected] wrote:
Export
__dpll_device_change_ntf()so that drivers can send device change notifications from within device callbacks, which are already called underdpll_lock. Usingdpll_device_change_ntf()in that context would deadlock.Add
lockdep_assert_held()to catch misuse without the lock held.Signed-off-by Ivan Vecera <[email protected]>
Ivan Vecera
maintainerPATCH 2/3 dpll: zl3073x: use __dpll_device_change_ntf() and remove change_work
In reply to Ivan VeceraThe change_work was introduced to send device change notifications from DPLL device callbacks without deadlocking on dpll_lock, since the callbacks are already invoked under that lock. Now that __dpll_device_change_ntf() is exported for callers that already hold dpll_lock, use it directly and remove the change_work infrastructure entirely.
This eliminates a race condition where change_work could be re-scheduled after cancel_work_sync() during device teardown, potentially causing the handler to dereference a freed or NULL dpll_dev pointer.
--- drivers/dpll/zl3073x/dpll.c | 26 +++++++++----------------- drivers/dpll/zl3073x/dpll.h | 2 -- 2 files changed, 9 insertions(+), 19 deletions(-)
drivers/dpll/zl3073x/dpll.c +9 -17
@@ -1079,15 +1079,6 @@ zl3073x_dpll_phase_offset_avg_factor_get(const struct dpll_device *dpll,return 0 ; } -static void -zl3073x_dpll_change_work (struct work_struct *work) -{ -struct zl3073x_dpll *zldpll; - - zldpll = container_of(work, struct zl3073x_dpll, change_work); -dpll_device_change_ntf (zldpll->dpll_dev); -} - static int zl3073x_dpll_phase_offset_avg_factor_set(const struct dpll_device *dpll, void *dpll_priv, u32 factor,
@@ -1113,8 +1104,10 @@ zl3073x_dpll_phase_offset_avg_factor_set(const struct dpll_device *dpll,* we have to send a notification for other DPLL devices. */ list_for_each_entry (item, &zldpll->dev->dplls, list) { -if (item != zldpll) -schedule_work (&item->change_work); +struct dpll_device *dpll_dev =READ_ONCE (item->dpll_dev); + +if (item != zldpll && dpll_dev) +__dpll_device_change_ntf (dpll_dev); }return 0 ;
@@ -1627,13 +1620,13 @@ zl3073x_dpll_device_register(struct zl3073x_dpll *zldpll)static void zl3073x_dpll_device_unregister (struct zl3073x_dpll *zldpll) { -WARN (!zldpll->dpll_dev,"DPLL device is not registered\n" ); +struct dpll_device *dpll_dev =READ_ONCE (zldpll->dpll_dev); -cancel_work_sync (&zldpll->change_work); +WARN (!dpll_dev,"DPLL device is not registered\n" ); -dpll_device_unregister (zldpll->dpll_dev, &zldpll->ops, zldpll); -dpll_device_put (zldpll->dpll_dev, &zldpll->tracker); - zldpll->dpll_dev =NULL ; +WRITE_ONCE (zldpll->dpll_dev,NULL ); +dpll_device_unregister (dpll_dev, &zldpll->ops, zldpll); +dpll_device_put (dpll_dev, &zldpll->tracker); }/**
@@ -1926,7 +1919,6 @@ zl3073x_dpll_alloc(struct zl3073x_dev *zldev, u8 ch) zldpll->dev = zldev; zldpll->id = ch;INIT_LIST_HEAD (&zldpll->pins); -INIT_WORK (&zldpll->change_work, zl3073x_dpll_change_work);return zldpll; }
drivers/dpll/zl3073x/dpll.h +0 -2
@@ -21,7 +21,6 @@* @tracker: tracking object for the acquired reference * @lock_status: last saved DPLL lock status * @pins: list of pins -* @change_work: device change notification work */ struct zl3073x_dpll {struct list_head list;
@@ -35,7 +34,6 @@ struct zl3073x_dpll {dpll_tracker tracker;enum dpll_lock_status lock_status;struct list_head pins; -struct work_struct change_work; };struct zl3073x_dpll *zl3073x_dpll_alloc (struct zl3073x_dev *zldev,u8 ch);
Signature · 1 line
2.53.0
Ivan Vecera
maintainerRe: [PATCH net 2/3] dpll: zl3073x: use __dpll_device_change_ntf() and remove change_work
Quoted 7 lines · Ivan Vecera
The
change_workwas introduced to send device change notifications from DPLL device callbacks without deadlocking ondpll_lock, since the callbacks are already invoked under that lock. Now that__dpll_device_change_ntf()is exported for callers that already holddpll_lock, use it directly and remove thechange_workinfrastructure entirely.
Quoted 7 lines
This eliminates a race condition where
change_workcould be re-scheduled aftercancel_work_sync()during device teardown, potentially causing the handler to dereference a freed or NULLdpll_devpointer.Fixes 9363b4837659 ("dpll: zl3073x: Allow to configure phase offset averaging factor")Signed-off-by Ivan Vecera <[email protected]>
Hi Kuba & Paolo,
patchwork reported netdev/build_allmodconfig_warn failure for this patch. But it looks weird:
https://netdev-ctrl.bots.linux.dev/logs/build/1100767/14594344/build_allmodconfig_warn/stderr
I don't understand how this is related to this patch.
Thanks,
Ivan
Jakub Kicinski
maintainerRe: [PATCH net 2/3] dpll: zl3073x: use __dpll_device_change_ntf() and remove change_work
Quoted 16 lines · On Wed, 27 May 2026 09:51:43 +0200 Ivan Vecera wrote:
Quoted 7 lines · Ivan Vecera
The
change_workwas introduced to send device change notifications from DPLL device callbacks without deadlocking ondpll_lock, since the callbacks are already invoked under that lock. Now that__dpll_device_change_ntf()is exported for callers that already holddpll_lock, use it directly and remove thechange_workinfrastructure entirely.Quoted 7 lines
This eliminates a race condition where
change_workcould be re-scheduled aftercancel_work_sync()during device teardown, potentially causing the handler to dereference a freed or NULLdpll_devpointer.Fixes 9363b4837659 ("dpll: zl3073x: Allow to configure phase offset averaging factor")Signed-off-by Ivan Vecera <[email protected]>
Quoted 8 lines
Hi Kuba & Paolo,
patchwork reported netdev/build_allmodconfig_warn failure for this patch. But it looks weird:
https://netdev-ctrl.bots.linux.dev/logs/build/1100767/14594344/build_allmodconfig_warn/stderr
I don't understand how this is related to this patch.
Sparse randomly generates this once a week on a seemingly random patch, I haven't dug into why. Safe to ignore.
Ivan Vecera
maintainerPATCH 3/3 dpll: zl3073x: make frequency monitor a per-device attribute
In reply to Ivan VeceraThe frequency monitoring feature uses shared hardware registers that measure input reference frequencies independently of individual DPLL channels. However, the freq_monitor flag was incorrectly placed in the per-DPLL structure, causing each channel to track its own enable/disable state independently.
Since the DPLL core calls measured_freq_get() only for the first pin registration, the measured_freq_check() in the periodic worker was gated by the per-DPLL freq_monitor flag of whichever channel happens to be checked. If the first DPLL channel had frequency monitoring disabled while another had it enabled, measurements were never reported.
Move freq_monitor from struct zl3073x_dpll to struct zl3073x_dev so all DPLL channels share a single flag, matching the hardware behavior. Update freq_monitor_set() to notify other DPLL devices about the change (like phase_offset_avg_factor_set() already does) and remove the mode-dependent guard in zl3073x_dpll_changes_check() since all input pin monitoring (pin state, phase offset, FFO, and measured frequency) works correctly in all DPLL modes.
--- drivers/dpll/zl3073x/core.c | 19 ++++++++----------- drivers/dpll/zl3073x/core.h | 4 +++- drivers/dpll/zl3073x/dpll.c | 29 ++++++++++++++--------------- drivers/dpll/zl3073x/dpll.h | 2 -- 4 files changed, 25 insertions(+), 29 deletions(-)
drivers/dpll/zl3073x/core.c +8 -11
@@ -762,18 +762,15 @@ zl3073x_dev_periodic_work(struct kthread_work *work)dev_warn (zldev->dev,"Failed to update phase offsets: %pe\n" ,ERR_PTR (rc)); -/* Update measured input reference frequencies if any DPLL has -* frequency monitoring enabled. +/* Update measured input reference frequencies if frequency +* monitoring is enabled. */ -list_for_each_entry (zldpll, &zldev->dplls, list) { -if (zldpll->freq_monitor) { - rc =zl3073x_ref_freq_meas_update (zldev); -if (rc) -dev_warn (zldev->dev, -"Failed to update measured frequencies: %pe\n" , -ERR_PTR (rc)); -break ; - } +if (zldev->freq_monitor) { + rc =zl3073x_ref_freq_meas_update (zldev); +if (rc) +dev_warn (zldev->dev, +"Failed to update measured frequencies: %pe\n" , +ERR_PTR (rc)); }/* Update references' fractional frequency offsets */
drivers/dpll/zl3073x/core.h +3 -1
@@ -57,6 +57,7 @@ struct zl3073x_chip_info {* @work: periodic work * @clock_id: clock id of the device * @phase_avg_factor: phase offset measurement averaging factor +* @freq_monitor: is frequency monitor enabled */ struct zl3073x_dev {struct device *dev;
@@ -77,9 +78,10 @@ struct zl3073x_dev {struct kthread_worker *kworker;struct kthread_delayed_work work; -/* Devlink parameters */ +/* Per-chip parameters */ u64 clock_id;u8 phase_avg_factor; +bool freq_monitor; };extern const struct regmap_config zl3073x_regmap_config;
drivers/dpll/zl3073x/dpll.c +14 -15
@@ -1212,7 +1212,7 @@ zl3073x_dpll_freq_monitor_get(const struct dpll_device *dpll, {struct zl3073x_dpll *zldpll = dpll_priv; -if (zldpll->freq_monitor) +if (zldpll->dev->freq_monitor) *state =DPLL_FEATURE_STATE_ENABLE ;else *state =DPLL_FEATURE_STATE_DISABLE ;
@@ -1226,9 +1226,19 @@ zl3073x_dpll_freq_monitor_set(const struct dpll_device *dpll,enum dpll_feature_state state, struct netlink_ext_ack *extack) { - struct zl3073x_dpll *zldpll = dpll_priv; + struct zl3073x_dpll *item, *zldpll = dpll_priv; - zldpll->freq_monitor = (state ==DPLL_FEATURE_STATE_ENABLE ); + zldpll->dev->freq_monitor = (state ==DPLL_FEATURE_STATE_ENABLE ); + +/* The frequency monitoring is common for all DPLL channels so after +* change we have to send a notification for other DPLL devices. +*/ +list_for_each_entry (item, &zldpll->dev->dplls, list) { +struct dpll_device *dpll_dev =READ_ONCE (item->dpll_dev); + +if (item != zldpll && dpll_dev) +__dpll_device_change_ntf (dpll_dev); + }return 0 ; }
@@ -1745,7 +1755,7 @@ zl3073x_dpll_pin_measured_freq_check(struct zl3073x_dpll_pin *pin)u8 ref_id;u32 freq; -if (!zldpll->freq_monitor) +if (!zldpll->dev->freq_monitor)return false; ref_id =zl3073x_input_pin_ref_get (pin->id);
@@ -1778,10 +1788,8 @@ zl3073x_dpll_changes_check(struct zl3073x_dpll *zldpll)struct zl3073x_dev *zldev = zldpll->dev;enum dpll_lock_status lock_status;struct device *dev = zldev->dev; -const struct zl3073x_chan *chan;struct zl3073x_dpll_pin *pin;int rc; -u8 mode; zldpll->check_count++;
@@ -1800,15 +1808,6 @@ zl3073x_dpll_changes_check(struct zl3073x_dpll *zldpll)dpll_device_change_ntf (zldpll->dpll_dev); } -/* Input pin monitoring does make sense only in automatic -* or forced reference modes. -*/ - chan =zl3073x_chan_state_get (zldev, zldpll->id); - mode =zl3073x_chan_mode_get (chan); -if (mode !=ZL_DPLL_MODE_REFSEL_MODE_AUTO && - mode !=ZL_DPLL_MODE_REFSEL_MODE_REFLOCK ) -return ; -/* Update phase offset latch registers for this DPLL if the phase * offset monitor feature is enabled. */
drivers/dpll/zl3073x/dpll.h +0 -2
@@ -15,7 +15,6 @@* @id: DPLL index * @check_count: periodic check counter * @phase_monitor: is phase offset monitor enabled -* @freq_monitor: is frequency monitor enabled * @ops: DPLL device operations for this instance * @dpll_dev: pointer to registered DPLL device * @tracker: tracking object for the acquired reference
@@ -28,7 +27,6 @@ struct zl3073x_dpll {u8 id;u8 check_count;bool phase_monitor; -bool freq_monitor;struct dpll_device_ops ops;struct dpll_device *dpll_dev;dpll_tracker tracker;
Signature · 1 line
2.53.0
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Tue, 26 May 2026 09:45:22 +0200 you wrote:
Three fixes for the zl3073x DPLL driver.
Patch 1 exports
__dpll_device_change_ntf()for use by drivers that need to send device change notifications from within callbacks already running underdpll_lock.
Quoted 6 lines
Patch 2 replaces the
change_workworkqueue mechanism with direct calls to__dpll_device_change_ntf(), eliminating a race condition where the work handler could dereference a freeddpll_devpointer during device teardown.[...]
Here is the summary with links:
- [net,1/3] dpll: export __dpll_device_change_ntf() for use under dpll_lock
https://git.kernel.org/netdev/net/c/20040b2a3cb9 - [net,2/3] dpll: zl3073x: use __dpll_device_change_ntf() and remove change_work https://git.kernel.org/netdev/net/c/d733f519f644 - [net,3/3] dpll: zl3073x: make frequency monitor a per-device attribute https://git.kernel.org/netdev/net/c/c1224569cef0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html