Skip to content

Commit ec8c1b9

Browse files
tombaWolfram Sang
authored andcommitted
i2c: atr: Fix lockdep for nested ATRs
When we have an ATR, and another ATR as a subdevice of the first ATR, we get lockdep warnings for the i2c_atr.lock and i2c_atr_chan.orig_addrs_lock. This is because lockdep uses a static key for the locks, and doesn't see the locks of the separate ATR instances as separate. Fix this by generating a dynamic lock key per lock instance. Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com> Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 7e6f4a0 commit ec8c1b9

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

drivers/i2c/i2c-atr.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ struct i2c_atr_alias_pool {
6868
* @atr: The parent I2C ATR
6969
* @chan_id: The ID of this channel
7070
* @alias_pairs_lock: Mutex protecting @alias_pairs
71+
* @alias_pairs_lock_key: Lock key for @alias_pairs_lock
7172
* @alias_pairs: List of @struct i2c_atr_alias_pair containing the
7273
* assigned aliases
7374
* @alias_pool: Pool of available client aliases
7475
*
7576
* @orig_addrs_lock: Mutex protecting @orig_addrs
77+
* @orig_addrs_lock_key: Lock key for @orig_addrs_lock
7678
* @orig_addrs: Buffer used to store the original addresses during transmit
7779
* @orig_addrs_size: Size of @orig_addrs
7880
*/
@@ -83,11 +85,13 @@ struct i2c_atr_chan {
8385

8486
/* Lock alias_pairs during attach/detach */
8587
struct mutex alias_pairs_lock;
88+
struct lock_class_key alias_pairs_lock_key;
8689
struct list_head alias_pairs;
8790
struct i2c_atr_alias_pool *alias_pool;
8891

8992
/* Lock orig_addrs during xfer */
9093
struct mutex orig_addrs_lock;
94+
struct lock_class_key orig_addrs_lock_key;
9195
u16 *orig_addrs;
9296
unsigned int orig_addrs_size;
9397
};
@@ -100,6 +104,7 @@ struct i2c_atr_chan {
100104
* @priv: Private driver data, set with i2c_atr_set_driver_data()
101105
* @algo: The &struct i2c_algorithm for adapters
102106
* @lock: Lock for the I2C bus segment (see &struct i2c_lock_operations)
107+
* @lock_key: Lock key for @lock
103108
* @max_adapters: Maximum number of adapters this I2C ATR can have
104109
* @alias_pool: Optional common pool of available client aliases
105110
* @i2c_nb: Notifier for remote client add & del events
@@ -115,6 +120,7 @@ struct i2c_atr {
115120
struct i2c_algorithm algo;
116121
/* lock for the I2C bus segment (see struct i2c_lock_operations) */
117122
struct mutex lock;
123+
struct lock_class_key lock_key;
118124
int max_adapters;
119125

120126
struct i2c_atr_alias_pool *alias_pool;
@@ -683,7 +689,8 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
683689
if (!atr)
684690
return ERR_PTR(-ENOMEM);
685691

686-
mutex_init(&atr->lock);
692+
lockdep_register_key(&atr->lock_key);
693+
mutex_init_with_key(&atr->lock, &atr->lock_key);
687694

688695
atr->parent = parent;
689696
atr->dev = dev;
@@ -711,6 +718,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
711718
i2c_atr_free_alias_pool(atr->alias_pool);
712719
err_destroy_mutex:
713720
mutex_destroy(&atr->lock);
721+
lockdep_unregister_key(&atr->lock_key);
714722
kfree(atr);
715723

716724
return ERR_PTR(ret);
@@ -727,6 +735,7 @@ void i2c_atr_delete(struct i2c_atr *atr)
727735
bus_unregister_notifier(&i2c_bus_type, &atr->i2c_nb);
728736
i2c_atr_free_alias_pool(atr->alias_pool);
729737
mutex_destroy(&atr->lock);
738+
lockdep_unregister_key(&atr->lock_key);
730739
kfree(atr);
731740
}
732741
EXPORT_SYMBOL_NS_GPL(i2c_atr_delete, "I2C_ATR");
@@ -761,8 +770,10 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
761770
chan->atr = atr;
762771
chan->chan_id = chan_id;
763772
INIT_LIST_HEAD(&chan->alias_pairs);
764-
mutex_init(&chan->alias_pairs_lock);
765-
mutex_init(&chan->orig_addrs_lock);
773+
lockdep_register_key(&chan->alias_pairs_lock_key);
774+
lockdep_register_key(&chan->orig_addrs_lock_key);
775+
mutex_init_with_key(&chan->alias_pairs_lock, &chan->alias_pairs_lock_key);
776+
mutex_init_with_key(&chan->orig_addrs_lock, &chan->orig_addrs_lock_key);
766777

767778
snprintf(chan->adap.name, sizeof(chan->adap.name), "i2c-%d-atr-%d",
768779
i2c_adapter_id(parent), chan_id);
@@ -839,6 +850,8 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
839850
fwnode_handle_put(dev_fwnode(&chan->adap.dev));
840851
mutex_destroy(&chan->orig_addrs_lock);
841852
mutex_destroy(&chan->alias_pairs_lock);
853+
lockdep_unregister_key(&chan->orig_addrs_lock_key);
854+
lockdep_unregister_key(&chan->alias_pairs_lock_key);
842855
kfree(chan);
843856
return ret;
844857
}
@@ -876,6 +889,8 @@ void i2c_atr_del_adapter(struct i2c_atr *atr, u32 chan_id)
876889
fwnode_handle_put(fwnode);
877890
mutex_destroy(&chan->orig_addrs_lock);
878891
mutex_destroy(&chan->alias_pairs_lock);
892+
lockdep_unregister_key(&chan->orig_addrs_lock_key);
893+
lockdep_unregister_key(&chan->alias_pairs_lock_key);
879894
kfree(chan->orig_addrs);
880895
kfree(chan);
881896
}

0 commit comments

Comments
 (0)