Skip to content

Commit

Permalink
i2c: core: fix lockdep warning for sparsely nested adapter chain
Browse files Browse the repository at this point in the history
When adapters are chained in a sparse manner (with intermediate MFD devices,
for instance) the code currently fails to use the correct subclass for
the adapter's bus_lock which leads to false-positive lockdep warnings.

Fix this by walking the entire pedigree of the device and count all
adapters along the way.

Signed-off-by: Daniel Mack <[email protected]>
  • Loading branch information
zonque committed Nov 8, 2023
1 parent dee4a4c commit efa9074
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/i2c/i2c-core-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,11 @@ static void i2c_adapter_dev_release(struct device *dev)
unsigned int i2c_adapter_depth(struct i2c_adapter *adapter)
{
unsigned int depth = 0;
struct device *parent;

while ((adapter = i2c_parent_is_i2c_adapter(adapter)))
depth++;
for (parent = adapter->dev.parent; parent; parent = parent->parent)
if (parent->type == &i2c_adapter_type)
depth++;

WARN_ONCE(depth >= MAX_LOCKDEP_SUBCLASSES,
"adapter depth exceeds lockdep subclass limit\n");
Expand Down

0 comments on commit efa9074

Please sign in to comment.