Skip to content

Commit 3996a4f

Browse files
viviendavem330
authored andcommitted
net: dsa: mv88e6xxx: assert SMI lock
It's easy to forget to lock the smi_mutex before calling the low-level _mv88e6xxx_reg_{read,write}, so add a assert_smi_lock function in them. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Acked-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ac00881 commit 3996a4f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/net/dsa/mv88e6xxx.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
#include <net/switchdev.h>
2525
#include "mv88e6xxx.h"
2626

27+
static void assert_smi_lock(struct dsa_switch *ds)
28+
{
29+
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
30+
31+
if (unlikely(!mutex_is_locked(&ps->smi_mutex))) {
32+
dev_err(ds->master_dev, "SMI lock not held!\n");
33+
dump_stack();
34+
}
35+
}
36+
2737
/* If the switch's ADDR[4:0] strap pins are strapped to zero, it will
2838
* use all 32 SMI bus addresses on its SMI bus, and all switch registers
2939
* will be directly accessible on some {device address,register address}
@@ -80,12 +90,13 @@ int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg)
8090
return ret & 0xffff;
8191
}
8292

83-
/* Must be called with SMI mutex held */
8493
static int _mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg)
8594
{
8695
struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
8796
int ret;
8897

98+
assert_smi_lock(ds);
99+
89100
if (bus == NULL)
90101
return -EINVAL;
91102

@@ -143,12 +154,13 @@ int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
143154
return 0;
144155
}
145156

146-
/* Must be called with SMI mutex held */
147157
static int _mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg,
148158
u16 val)
149159
{
150160
struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
151161

162+
assert_smi_lock(ds);
163+
152164
if (bus == NULL)
153165
return -EINVAL;
154166

@@ -204,15 +216,13 @@ int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr)
204216
return 0;
205217
}
206218

207-
/* Must be called with SMI mutex held */
208219
static int _mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum)
209220
{
210221
if (addr >= 0)
211222
return _mv88e6xxx_reg_read(ds, addr, regnum);
212223
return 0xffff;
213224
}
214225

215-
/* Must be called with SMI mutex held */
216226
static int _mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum,
217227
u16 val)
218228
{
@@ -538,7 +548,6 @@ void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
538548
mutex_unlock(&ps->smi_mutex);
539549
}
540550

541-
/* Must be called with SMI mutex held */
542551
static int _mv88e6xxx_stats_wait(struct dsa_switch *ds)
543552
{
544553
int ret;
@@ -553,7 +562,6 @@ static int _mv88e6xxx_stats_wait(struct dsa_switch *ds)
553562
return -ETIMEDOUT;
554563
}
555564

556-
/* Must be called with SMI mutex held */
557565
static int _mv88e6xxx_stats_snapshot(struct dsa_switch *ds, int port)
558566
{
559567
int ret;
@@ -576,7 +584,6 @@ static int _mv88e6xxx_stats_snapshot(struct dsa_switch *ds, int port)
576584
return 0;
577585
}
578586

579-
/* Must be called with SMI mutex held */
580587
static void _mv88e6xxx_stats_read(struct dsa_switch *ds, int stat, u32 *val)
581588
{
582589
u32 _val;
@@ -789,7 +796,6 @@ void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
789796
}
790797
}
791798

792-
/* Must be called with SMI lock held */
793799
static int _mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset,
794800
u16 mask)
795801
{
@@ -839,14 +845,12 @@ int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds)
839845
GLOBAL2_EEPROM_OP_BUSY);
840846
}
841847

842-
/* Must be called with SMI lock held */
843848
static int _mv88e6xxx_atu_wait(struct dsa_switch *ds)
844849
{
845850
return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_ATU_OP,
846851
GLOBAL_ATU_OP_BUSY);
847852
}
848853

849-
/* Must be called with SMI mutex held */
850854
static int _mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr,
851855
int regnum)
852856
{
@@ -865,7 +869,6 @@ static int _mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr,
865869
return _mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_SMI_DATA);
866870
}
867871

868-
/* Must be called with SMI mutex held */
869872
static int _mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr,
870873
int regnum, u16 val)
871874
{

0 commit comments

Comments
 (0)