Skip to content

Commit b93984c

Browse files
daviddaneydavem330
authored andcommitted
netdev/phy: Fixup lockdep warnings in mdio-mux.c
With lockdep enabled we get: ============================================= [ INFO: possible recursive locking detected ] 3.4.4-Cavium-Octeon+ raspberrypi#313 Not tainted --------------------------------------------- kworker/u:1/36 is trying to acquire lock: (&bus->mdio_lock){+.+...}, at: [<ffffffff813da7e8>] mdio_mux_read+0x38/0xa0 but task is already holding lock: (&bus->mdio_lock){+.+...}, at: [<ffffffff813d79e4>] mdiobus_read+0x44/0x88 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&bus->mdio_lock); lock(&bus->mdio_lock); *** DEADLOCK *** May be due to missing lock nesting notation . . . This is a false positive, since we are indeed using 'nested' locking, we need to use mutex_lock_nested(). Now in theory we can stack multiple MDIO multiplexers, but that would require passing the nesting level (which is difficult to know) to mutex_lock_nested(). Instead we assume the simple case of a single level of nesting. Since these are only warning messages, it isn't so important to solve the general case. Signed-off-by: David Daney <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d4e4164 commit b93984c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/net/phy/mdio-mux.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ static int mdio_mux_read(struct mii_bus *bus, int phy_id, int regnum)
4646
struct mdio_mux_parent_bus *pb = cb->parent;
4747
int r;
4848

49-
mutex_lock(&pb->mii_bus->mdio_lock);
49+
/* In theory multiple mdio_mux could be stacked, thus creating
50+
* more than a single level of nesting. But in practice,
51+
* SINGLE_DEPTH_NESTING will cover the vast majority of use
52+
* cases. We use it, instead of trying to handle the general
53+
* case.
54+
*/
55+
mutex_lock_nested(&pb->mii_bus->mdio_lock, SINGLE_DEPTH_NESTING);
5056
r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data);
5157
if (r)
5258
goto out;
@@ -71,7 +77,7 @@ static int mdio_mux_write(struct mii_bus *bus, int phy_id,
7177

7278
int r;
7379

74-
mutex_lock(&pb->mii_bus->mdio_lock);
80+
mutex_lock_nested(&pb->mii_bus->mdio_lock, SINGLE_DEPTH_NESTING);
7581
r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data);
7682
if (r)
7783
goto out;

0 commit comments

Comments
 (0)