Skip to content

Commit 2b52a4b

Browse files
Sven Van Asbroeckkuba-moo
authored andcommitted
lan743x: fix "BUG: invalid wait context" when setting rx mode
In the net core, the struct net_device_ops -> ndo_set_rx_mode() callback is called with the dev->addr_list_lock spinlock held. However, this driver's ndo_set_rx_mode callback eventually calls lan743x_dp_write(), which acquires a mutex. Mutex acquisition may sleep, and this is not allowed when holding a spinlock. Fix by removing the dp_lock mutex entirely. Its purpose is to prevent concurrent accesses to the data port. No concurrent accesses are possible, because the dev->addr_list_lock spinlock in the core only lets through one thread at a time. Fixes: 23f0703 ("lan743x: Add main source files for new lan743x driver") Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com> Link: https://lore.kernel.org/r/20201109203828.5115-1-TheSven73@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2bae900 commit 2b52a4b

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

drivers/net/ethernet/microchip/lan743x_main.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,12 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter)
674674
static int lan743x_dp_write(struct lan743x_adapter *adapter,
675675
u32 select, u32 addr, u32 length, u32 *buf)
676676
{
677-
int ret = -EIO;
678677
u32 dp_sel;
679678
int i;
680679

681-
mutex_lock(&adapter->dp_lock);
682680
if (lan743x_csr_wait_for_bit(adapter, DP_SEL, DP_SEL_DPRDY_,
683681
1, 40, 100, 100))
684-
goto unlock;
682+
return -EIO;
685683
dp_sel = lan743x_csr_read(adapter, DP_SEL);
686684
dp_sel &= ~DP_SEL_MASK_;
687685
dp_sel |= select;
@@ -693,13 +691,10 @@ static int lan743x_dp_write(struct lan743x_adapter *adapter,
693691
lan743x_csr_write(adapter, DP_CMD, DP_CMD_WRITE_);
694692
if (lan743x_csr_wait_for_bit(adapter, DP_SEL, DP_SEL_DPRDY_,
695693
1, 40, 100, 100))
696-
goto unlock;
694+
return -EIO;
697695
}
698-
ret = 0;
699696

700-
unlock:
701-
mutex_unlock(&adapter->dp_lock);
702-
return ret;
697+
return 0;
703698
}
704699

705700
static u32 lan743x_mac_mii_access(u16 id, u16 index, int read)
@@ -2735,7 +2730,6 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter,
27352730

27362731
adapter->intr.irq = adapter->pdev->irq;
27372732
lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF);
2738-
mutex_init(&adapter->dp_lock);
27392733

27402734
ret = lan743x_gpio_init(adapter);
27412735
if (ret)

drivers/net/ethernet/microchip/lan743x_main.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,6 @@ struct lan743x_adapter {
712712
struct lan743x_csr csr;
713713
struct lan743x_intr intr;
714714

715-
/* lock, used to prevent concurrent access to data port */
716-
struct mutex dp_lock;
717-
718715
struct lan743x_gpio gpio;
719716
struct lan743x_ptp ptp;
720717

0 commit comments

Comments
 (0)