@@ -35,7 +35,7 @@ LOG_MODULE_REGISTER(net_dhcpv4, CONFIG_NET_DHCPV4_LOG_LEVEL);
3535static K_MUTEX_DEFINE (lock );
3636
3737static sys_slist_t dhcpv4_ifaces ;
38- static struct k_delayed_work timeout_work ;
38+ static struct k_work_delayable timeout_work ;
3939
4040static struct net_mgmt_event_callback mgmt4_cb ;
4141
@@ -278,14 +278,16 @@ static struct net_pkt *dhcpv4_create_message(struct net_if *iface, uint8_t type,
278278 return NULL ;
279279}
280280
281+ /* Must be invoked with lock held. */
281282static void dhcpv4_immediate_timeout (struct net_if_dhcpv4 * dhcpv4 )
282283{
283284 NET_DBG ("force timeout dhcpv4=%p" , dhcpv4 );
284285 dhcpv4 -> timer_start = k_uptime_get () - 1 ;
285286 dhcpv4 -> request_time = 0U ;
286- k_delayed_work_submit (& timeout_work , K_NO_WAIT );
287+ k_work_reschedule (& timeout_work , K_NO_WAIT );
287288}
288289
290+ /* Must be invoked with lock held. */
289291static void dhcpv4_set_timeout (struct net_if_dhcpv4 * dhcpv4 ,
290292 uint32_t timeout )
291293{
@@ -297,9 +299,10 @@ static void dhcpv4_set_timeout(struct net_if_dhcpv4 *dhcpv4,
297299 * event; also this timeout may replace the current timeout
298300 * event. Delegate scheduling to the timeout manager.
299301 */
300- k_delayed_work_submit (& timeout_work , K_NO_WAIT );
302+ k_work_reschedule (& timeout_work , K_NO_WAIT );
301303}
302304
305+ /* Must be invoked with lock held */
303306static uint32_t dhcpv4_update_message_timeout (struct net_if_dhcpv4 * dhcpv4 )
304307{
305308 uint32_t timeout ;
@@ -526,6 +529,7 @@ static void dhcpv4_enter_requesting(struct net_if *iface)
526529 dhcpv4_send_request (iface );
527530}
528531
532+ /* Must be invoked with lock held */
529533static void dhcpv4_enter_bound (struct net_if * iface )
530534{
531535 uint32_t renewal_time ;
@@ -653,8 +657,8 @@ static void dhcpv4_timeout(struct k_work *work)
653657 if (timeout_update != UINT32_MAX ) {
654658 NET_DBG ("Waiting for %us" , timeout_update );
655659
656- k_delayed_work_submit (& timeout_work ,
657- K_SECONDS (timeout_update ));
660+ k_work_reschedule (& timeout_work ,
661+ K_SECONDS (timeout_update ));
658662 }
659663}
660664
@@ -900,6 +904,7 @@ static inline void dhcpv4_handle_msg_offer(struct net_if *iface)
900904 }
901905}
902906
907+ /* Must be invoked with lock held */
903908static void dhcpv4_handle_msg_ack (struct net_if * iface )
904909{
905910 switch (iface -> config .dhcpv4 .state ) {
@@ -951,6 +956,7 @@ static void dhcpv4_handle_msg_nak(struct net_if *iface)
951956 }
952957}
953958
959+ /* Takes and releases lock */
954960static void dhcpv4_handle_reply (struct net_if * iface ,
955961 enum dhcpv4_msg_type msg_type )
956962{
@@ -1226,7 +1232,10 @@ void net_dhcpv4_stop(struct net_if *iface)
12261232 & iface -> config .dhcpv4 .node );
12271233
12281234 if (sys_slist_is_empty (& dhcpv4_ifaces )) {
1229- k_delayed_work_cancel (& timeout_work );
1235+ /* Best effort cancel. Handler is safe to invoke if
1236+ * cancellation is unsuccessful.
1237+ */
1238+ (void )k_work_cancel_delayable (& timeout_work );
12301239 net_mgmt_del_event_callback (& mgmt4_cb );
12311240 }
12321241
@@ -1262,7 +1271,7 @@ int net_dhcpv4_init(void)
12621271 return ret ;
12631272 }
12641273
1265- k_delayed_work_init (& timeout_work , dhcpv4_timeout );
1274+ k_work_init_delayable (& timeout_work , dhcpv4_timeout );
12661275
12671276 /* Catch network interface UP or DOWN events and renew the address
12681277 * if interface is coming back up again.
0 commit comments