i2c: core: fix lockdep warning for sparsely nested adapter chain
Subsystems (2)
PATCH 1/1 i2c: core: fix lockdep warning for sparsely nested adapter chain
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 instead of just checking the immediate parent.
---
This hit me when during the development of a driver stack that isn't submitted mainline yet. This patch could however be discussed independently I think.
drivers/i2c/i2c-core-base.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +4 -2
@@ -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" );
Signature · 1 line
2.41.0
Hi Daniel,
Quoted 1 line · Daniel Mack
When adapters are chained in a sparse manner (with intermediate MFD devices,
So, you have an MFD including an i2c-mux or something?
Quoted 5 lines
for instance) the code currently fails to use the correct subclass for the adapter's
bus_lockwhich leads to false-positive lockdep warnings.Fix this by walking the entire pedigree of the device and count all adapters along the way instead of just checking the immediate parent.
Sounds reasonable to me.
Quoted 6 lines
Signed-off-by Daniel Mack <[email protected]>---
This hit me when during the development of a driver stack that isn't submitted mainline yet. This patch could however be discussed independently I think.
Yes, it can :)
Quoted 9 lines
drivers/i2c/i2c-core-base.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/i2c/i2c-core-base.c +0
-0
drivers/i2c/i2c-core-base.c static void i2c_adapter_dev_release(struct device *dev) · line 1193
Quoted 6 lines
drivers/i2c/i2c-core-base.c +1
-1@@ -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)))
I never noticed we overwrite the 'adapter' function argument. Much better with your version and the local variable.
drivers/i2c/i2c-core-base.c static void i2c_adapter_dev_release(struct device *dev) · line 1196
Quoted 4 lines
drivers/i2c/i2c-core-base.c +3
-1- depth++; +for (parent = adapter->dev.parent; parent; parent = parent->parent) +if (parent->type == &i2c_adapter_type) + depth++;
I am not sure myself. Is the code explaining itself or should we add a short comment why we use a for-loop? I tend to leave it as is.
Thanks for this patch!
Wolfram
Wolfram Sang
AppliedQuoted 8 lines · Daniel Mack
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_lockwhich leads to false-positive lockdep warnings.Fix this by walking the entire pedigree of the device and count all adapters along the way instead of just checking the immediate parent.
Signed-off-by Daniel Mack <[email protected]>
Applied to for-next, thanks!