batman-adv: dat: initialize purge work before hash allocation
Sven Eckelmann
maintainerPATCH 1/1 batman-adv: dat: initialize purge work before hash allocation
batadv_dat_init() only initializes bat_priv->dat.work after the hash table was allocated successfully. batadv_dat_free() unconditionally calls disable_delayed_work_sync() on it.
This is currently not a problem: if batadv_mesh_init() fails, batadv_dat_free() is never called. But as this might change in the future, initialize the delayed work before anything in batadv_dat_init() can fail to make sure that batadv_dat_free() always operates on an initialized work item.
--- net/batman-adv/distributed-arp-table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/distributed-arp-table.c +2 -1
@@ -894,12 +894,13 @@ int batadv_dat_init(struct batadv_priv *bat_priv)if (bat_priv->dat.hash)return 0 ; +INIT_DELAYED_WORK (&bat_priv->dat.work, batadv_dat_purge); + bat_priv->dat.hash =batadv_hash_new (1024 );if (!bat_priv->dat.hash)return -ENOMEM ; -INIT_DELAYED_WORK (&bat_priv->dat.work, batadv_dat_purge);batadv_dat_start_timer (bat_priv); batadv_tvlv_handler_register(bat_priv, batadv_dat_tvlv_ogm_handler_v1,
---
base-commit: 4fa5cbac90fa7b8936779b4313debb3d89701c59
change-id: 20261004-dat-uninitialized-worker-d393c8bf8415
Best regards,
Signature · 1 line
Sven Eckelmann <[email protected]>
Sven Eckelmann
maintainerQuoted 9 lines · On Sunday, 4 October 2026 10:21:58 CEST Sven Eckelmann wrote:
batadv_dat_init()only initializesbat_priv->dat.workafter the hash table was allocated successfully.batadv_dat_free()unconditionally callsdisable_delayed_work_sync()on it.This is currently not a problem: if
batadv_mesh_init()fails,batadv_dat_free()is never called. But as this might change in the future, initialize the delayed work before anything inbatadv_dat_init()can fail to make sure thatbatadv_dat_free()always operates on an initialized work item.
I think I will reject this patch because it is a little bit too defensive. Instead, I will simply reply to Sashiko that this isn't reachable. Similar to the batadv_v_ogm_free()'s mutex_lock() which isn't reachable when the alloc in batadv_v_ogm_init fails.
Regards,
Sven