Skip to content

Commit 5dbe296

Browse files
committed
driver/net: replace net_lock with netdev_lock.
modify the code of the adapted protocol stack to avoid deadlocks and the logic that cannot be protected by locks after modification. Signed-off-by: zhanghongyu <[email protected]>
1 parent 58047f9 commit 5dbe296

File tree

17 files changed

+90
-90
lines changed

17 files changed

+90
-90
lines changed

arch/sim/src/sim/sim_cansock.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ static int sim_can_txavail(struct net_driver_s *dev)
134134

135135
/* Ignore the notification if the interface is not yet up */
136136

137-
net_lock();
137+
netdev_lock(dev);
138138
if (IFF_IS_UP(priv->dev.d_flags))
139139
{
140140
devif_poll(&priv->dev, sim_can_txpoll);
141141
}
142142

143-
net_unlock();
143+
netdev_unlock(dev);
144144

145145
return OK;
146146
}
@@ -189,7 +189,7 @@ static void sim_can_work(void *arg)
189189
* in priv->dev.d_len
190190
*/
191191

192-
net_lock();
192+
netdev_lock(&priv->dev);
193193
priv->dev.d_len = ret;
194194
priv->dev.d_buf = (FAR uint8_t *)&hframe;
195195

@@ -198,7 +198,7 @@ static void sim_can_work(void *arg)
198198
NETDEV_RXPACKETS(&priv->dev);
199199

200200
can_input(&priv->dev);
201-
net_unlock();
201+
netdev_unlock(&priv->dev);
202202
}
203203

204204
nodata:

drivers/net/enc28j60.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ static void enc_irqworker(FAR void *arg)
15451545

15461546
/* Get exclusive access to both the network and the SPI bus. */
15471547

1548-
net_lock();
1548+
netdev_lock(&priv->dev);
15491549
enc_lock(priv);
15501550

15511551
/* Disable further interrupts by clearing the global interrupt enable bit.
@@ -1739,7 +1739,7 @@ static void enc_irqworker(FAR void *arg)
17391739
/* Release lock on the SPI bus and the network */
17401740

17411741
enc_unlock(priv);
1742-
net_unlock();
1742+
netdev_unlock(&priv->dev);
17431743
}
17441744

17451745
/****************************************************************************
@@ -1812,7 +1812,7 @@ static void enc_toworker(FAR void *arg)
18121812

18131813
/* Get exclusive access to the network */
18141814

1815-
net_lock();
1815+
netdev_lock(&priv->dev);
18161816

18171817
/* Increment statistics and dump debug info */
18181818

@@ -1834,7 +1834,7 @@ static void enc_toworker(FAR void *arg)
18341834

18351835
/* Release lock on the network */
18361836

1837-
net_unlock();
1837+
netdev_unlock(&priv->dev);
18381838
}
18391839

18401840
/****************************************************************************

drivers/net/encx24j600.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ static void enc_irqworker(FAR void *arg)
17351735

17361736
/* Get exclusive access to both the network and the SPI bus. */
17371737

1738-
net_lock();
1738+
netdev_lock(&priv->dev);
17391739
enc_lock(priv);
17401740

17411741
/* A good practice is for the host controller to clear the Global Interrupt
@@ -1884,7 +1884,7 @@ static void enc_irqworker(FAR void *arg)
18841884
/* Release lock on the SPI bus and the network */
18851885

18861886
enc_unlock(priv);
1887-
net_unlock();
1887+
netdev_unlock(&priv->dev);
18881888
}
18891889

18901890
/****************************************************************************
@@ -1957,7 +1957,7 @@ static void enc_toworker(FAR void *arg)
19571957

19581958
/* Get exclusive access to the network. */
19591959

1960-
net_lock();
1960+
netdev_lock(&priv->dev);
19611961

19621962
/* Increment statistics and dump debug info */
19631963

@@ -1979,7 +1979,7 @@ static void enc_toworker(FAR void *arg)
19791979

19801980
/* Release the network */
19811981

1982-
net_unlock();
1982+
netdev_unlock(&priv->dev);
19831983
}
19841984

19851985
/****************************************************************************

drivers/net/ftmac100.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ static void ftmac100_interrupt_work(FAR void *arg)
809809

810810
/* Process pending Ethernet interrupts */
811811

812-
net_lock();
812+
netdev_lock(&priv->ft_dev);
813813
status = priv->status;
814814

815815
ninfo("status=%08x(%08x) BASE=%p ISR=%p PHYCR=%p\n",
@@ -883,7 +883,7 @@ static void ftmac100_interrupt_work(FAR void *arg)
883883
putreg32 (INT_MASK_ALL_ENABLED, &iobase->imr);
884884

885885
ninfo("ISR-done\n");
886-
net_unlock();
886+
netdev_unlock(&priv->ft_dev);
887887

888888
/* Re-enable Ethernet interrupts */
889889

@@ -972,12 +972,12 @@ static void ftmac100_txtimeout_work(FAR void *arg)
972972

973973
/* Process pending Ethernet interrupts */
974974

975-
net_lock();
975+
netdev_lock(&priv->ft_dev);
976976

977977
/* Then poll the network for new XMIT data */
978978

979979
devif_poll(&priv->ft_dev, ftmac100_txpoll);
980-
net_unlock();
980+
netdev_unlock(&priv->ft_dev);
981981
}
982982

983983
/****************************************************************************
@@ -1137,7 +1137,7 @@ static void ftmac100_txavail_work(FAR void *arg)
11371137

11381138
/* Perform the poll */
11391139

1140-
net_lock();
1140+
netdev_lock(&priv->ft_dev);
11411141

11421142
/* Ignore the notification if the interface is not yet up */
11431143

@@ -1152,7 +1152,7 @@ static void ftmac100_txavail_work(FAR void *arg)
11521152
devif_poll(&priv->ft_dev, ftmac100_txpoll);
11531153
}
11541154

1155-
net_unlock();
1155+
netdev_unlock(&priv->ft_dev);
11561156
}
11571157

11581158
/****************************************************************************

drivers/net/lan91c111.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ static void lan91c111_interrupt_work(FAR void *arg)
812812
* thread has been configured.
813813
*/
814814

815-
net_lock();
815+
netdev_lock(dev);
816816

817817
/* Process pending Ethernet interrupts */
818818

@@ -873,7 +873,7 @@ static void lan91c111_interrupt_work(FAR void *arg)
873873
}
874874
}
875875

876-
net_unlock();
876+
netdev_unlock(dev);
877877

878878
/* Re-enable Ethernet interrupts */
879879

@@ -949,7 +949,7 @@ static int lan91c111_ifup(FAR struct net_driver_s *dev)
949949
dev->d_ipv6addr[6], dev->d_ipv6addr[7]);
950950
#endif
951951

952-
net_lock();
952+
netdev_lock(dev);
953953

954954
/* Initialize PHYs, Ethernet interface, and setup up Ethernet interrupts */
955955

@@ -974,7 +974,7 @@ static int lan91c111_ifup(FAR struct net_driver_s *dev)
974974

975975
copyto16(priv, ADDR0_REG, &dev->d_mac.ether, sizeof(dev->d_mac.ether));
976976

977-
net_unlock();
977+
netdev_unlock(dev);
978978

979979
/* Enable the Ethernet interrupt */
980980

@@ -1056,7 +1056,7 @@ static void lan91c111_txavail_work(FAR void *arg)
10561056
* thread has been configured.
10571057
*/
10581058

1059-
net_lock();
1059+
netdev_lock(dev);
10601060

10611061
/* Ignore the notification if the interface is not yet up */
10621062

@@ -1074,7 +1074,7 @@ static void lan91c111_txavail_work(FAR void *arg)
10741074
}
10751075
}
10761076

1077-
net_unlock();
1077+
netdev_unlock(dev);
10781078
}
10791079

10801080
/****************************************************************************
@@ -1187,9 +1187,9 @@ static int lan91c111_addmac(FAR struct net_driver_s *dev,
11871187

11881188
/* Add the MAC address to the hardware multicast routing table */
11891189

1190-
net_lock();
1190+
netdev_lock(dev);
11911191
modifyreg16(priv, MCAST_REG1 + off, 0, 1 << bit);
1192-
net_unlock();
1192+
netdev_unlock(dev);
11931193

11941194
return OK;
11951195
}
@@ -1234,9 +1234,9 @@ static int lan91c111_rmmac(FAR struct net_driver_s *dev,
12341234

12351235
/* Remove the MAC address from the hardware multicast routing table */
12361236

1237-
net_lock();
1237+
netdev_lock(dev);
12381238
modifyreg16(priv, MCAST_REG1 + off, 1 << bit, 0);
1239-
net_unlock();
1239+
netdev_unlock(dev);
12401240

12411241
return OK;
12421242
}
@@ -1269,7 +1269,7 @@ static int lan91c111_ioctl(FAR struct net_driver_s *dev, int cmd,
12691269
FAR struct mii_ioctl_data_s *req = (FAR void *)arg;
12701270
int ret = OK;
12711271

1272-
net_lock();
1272+
netdev_lock(dev);
12731273

12741274
/* Decode and dispatch the driver-specific IOCTL command */
12751275

@@ -1292,7 +1292,7 @@ static int lan91c111_ioctl(FAR struct net_driver_s *dev, int cmd,
12921292
ret = -ENOTTY; /* Special return value for this case */
12931293
}
12941294

1295-
net_unlock();
1295+
netdev_unlock(dev);
12961296
return ret;
12971297
}
12981298
#endif

drivers/net/lan9250.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ static void lan9250_txavail_work(FAR void *arg)
15251525
* thread has been configured.
15261526
*/
15271527

1528-
net_lock();
1528+
netdev_lock(dev);
15291529
lan9250_lock_spi(priv);
15301530

15311531
/* Ignore the notification if the interface is not yet up */
@@ -1544,7 +1544,7 @@ static void lan9250_txavail_work(FAR void *arg)
15441544
/* Release lock on the SPI bus and the network */
15451545

15461546
lan9250_unlock_spi(priv);
1547-
net_unlock();
1547+
netdev_unlock(dev);
15481548
}
15491549

15501550
/****************************************************************************
@@ -1798,7 +1798,7 @@ static void lan9250_int_worker(FAR void *arg)
17981798

17991799
/* Get exclusive access to both the network and the SPI bus. */
18001800

1801-
net_lock();
1801+
netdev_lock(&priv->dev);
18021802
lan9250_lock_spi(priv);
18031803

18041804
/* There is no infinite loop check... if there are always pending
@@ -1985,7 +1985,7 @@ static void lan9250_int_worker(FAR void *arg)
19851985
/* Release lock on the SPI bus and the network */
19861986

19871987
lan9250_unlock_spi(priv);
1988-
net_unlock();
1988+
netdev_unlock(&priv->dev);
19891989

19901990
/* Enable ISR_GPIO interrupts after unlocking net so that application
19911991
* could have chance to process Ethernet packet and free iob.
@@ -2061,7 +2061,7 @@ static void lan9250_txtout_worker(FAR void *arg)
20612061

20622062
/* Get exclusive access to the network */
20632063

2064-
net_lock();
2064+
netdev_lock(&priv->dev);
20652065

20662066
/* Increment statistics and dump debug info */
20672067

@@ -2083,7 +2083,7 @@ static void lan9250_txtout_worker(FAR void *arg)
20832083

20842084
/* Release lock on the network */
20852085

2086-
net_unlock();
2086+
netdev_unlock(&priv->dev);
20872087
}
20882088

20892089
/****************************************************************************

drivers/net/loopback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static void lo_txavail_work(FAR void *arg)
194194

195195
/* Ignore the notification if the interface is not yet up */
196196

197-
net_lock();
197+
netdev_lock(&priv->lo_dev);
198198
if (priv->lo_bifup)
199199
{
200200
/* Reuse the devif_loopback() logic, Polling all pending events until
@@ -204,7 +204,7 @@ static void lo_txavail_work(FAR void *arg)
204204
while (devif_poll(&priv->lo_dev, NULL));
205205
}
206206

207-
net_unlock();
207+
netdev_unlock(&priv->lo_dev);
208208
}
209209

210210
/****************************************************************************

drivers/net/skeleton.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ static void skel_interrupt_work(FAR void *arg)
466466
* thread has been configured.
467467
*/
468468

469-
net_lock();
469+
netdev_lock(&priv->sk_dev);
470470

471471
/* Process pending Ethernet interrupts */
472472

@@ -484,7 +484,7 @@ static void skel_interrupt_work(FAR void *arg)
484484
*/
485485

486486
skel_txdone(priv);
487-
net_unlock();
487+
netdev_unlock(&priv->sk_dev);
488488

489489
/* Re-enable Ethernet interrupts */
490490

@@ -564,7 +564,7 @@ static void skel_txtimeout_work(FAR void *arg)
564564
* thread has been configured.
565565
*/
566566

567-
net_lock();
567+
netdev_lock(&priv->sk_dev);
568568

569569
/* Increment statistics and dump debug info */
570570

@@ -575,7 +575,7 @@ static void skel_txtimeout_work(FAR void *arg)
575575
/* Then poll the network for new XMIT data */
576576

577577
devif_poll(&priv->sk_dev, skel_txpoll);
578-
net_unlock();
578+
netdev_unlock(&priv->sk_dev);
579579
}
580580

581581
/****************************************************************************
@@ -731,7 +731,7 @@ static void skel_txavail_work(FAR void *arg)
731731
* thread has been configured.
732732
*/
733733

734-
net_lock();
734+
netdev_lock(&priv->sk_dev);
735735

736736
/* Ignore the notification if the interface is not yet up */
737737

@@ -744,7 +744,7 @@ static void skel_txavail_work(FAR void *arg)
744744
devif_poll(&priv->sk_dev, skel_txpoll);
745745
}
746746

747-
net_unlock();
747+
netdev_unlock(&priv->sk_dev);
748748
}
749749

750750
/****************************************************************************

0 commit comments

Comments
 (0)