Skip to content

Commit 90d130a

Browse files
author
Paolo Abeni
committed
Merge branch 'fixes-on-the-open-alliance-tc6-10base-t1x-mac-phy-support-generic-lib'
Parthiban Veerasooran says: ==================== Fixes on the OPEN Alliance TC6 10BASE-T1x MAC-PHY support generic lib This patch series contain the below fixes. - Infinite loop error when tx credits becomes 0. - Race condition between tx skb reference pointers. v2: - Added mutex lock to protect tx skb reference handling. v3: - Added mutex protection in assigning new tx skb to waiting_tx_skb pointer. - Explained the possible scenario for the race condition with the time diagram in the commit message. v4: - Replaced mutex with spin_lock_bh() variants as the start_xmit runs in BH/softirq context which can't take sleeping locks. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 94901b7 + e592b51 commit 90d130a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/net/ethernet/oa_tc6.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct oa_tc6 {
113113
struct mii_bus *mdiobus;
114114
struct spi_device *spi;
115115
struct mutex spi_ctrl_lock; /* Protects spi control transfer */
116+
spinlock_t tx_skb_lock; /* Protects tx skb handling */
116117
void *spi_ctrl_tx_buf;
117118
void *spi_ctrl_rx_buf;
118119
void *spi_data_tx_buf;
@@ -1004,8 +1005,10 @@ static u16 oa_tc6_prepare_spi_tx_buf_for_tx_skbs(struct oa_tc6 *tc6)
10041005
for (used_tx_credits = 0; used_tx_credits < tc6->tx_credits;
10051006
used_tx_credits++) {
10061007
if (!tc6->ongoing_tx_skb) {
1008+
spin_lock_bh(&tc6->tx_skb_lock);
10071009
tc6->ongoing_tx_skb = tc6->waiting_tx_skb;
10081010
tc6->waiting_tx_skb = NULL;
1011+
spin_unlock_bh(&tc6->tx_skb_lock);
10091012
}
10101013
if (!tc6->ongoing_tx_skb)
10111014
break;
@@ -1111,8 +1114,9 @@ static int oa_tc6_spi_thread_handler(void *data)
11111114
/* This kthread will be waken up if there is a tx skb or mac-phy
11121115
* interrupt to perform spi transfer with tx chunks.
11131116
*/
1114-
wait_event_interruptible(tc6->spi_wq, tc6->waiting_tx_skb ||
1115-
tc6->int_flag ||
1117+
wait_event_interruptible(tc6->spi_wq, tc6->int_flag ||
1118+
(tc6->waiting_tx_skb &&
1119+
tc6->tx_credits) ||
11161120
kthread_should_stop());
11171121

11181122
if (kthread_should_stop())
@@ -1209,7 +1213,9 @@ netdev_tx_t oa_tc6_start_xmit(struct oa_tc6 *tc6, struct sk_buff *skb)
12091213
return NETDEV_TX_OK;
12101214
}
12111215

1216+
spin_lock_bh(&tc6->tx_skb_lock);
12121217
tc6->waiting_tx_skb = skb;
1218+
spin_unlock_bh(&tc6->tx_skb_lock);
12131219

12141220
/* Wake spi kthread to perform spi transfer */
12151221
wake_up_interruptible(&tc6->spi_wq);
@@ -1239,6 +1245,7 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev)
12391245
tc6->netdev = netdev;
12401246
SET_NETDEV_DEV(netdev, &spi->dev);
12411247
mutex_init(&tc6->spi_ctrl_lock);
1248+
spin_lock_init(&tc6->tx_skb_lock);
12421249

12431250
/* Set the SPI controller to pump at realtime priority */
12441251
tc6->spi->rt = true;

0 commit comments

Comments
 (0)