GBMC: i2c: npcm: Add lockdep assertions for bus->lock

Many functions in this driver modify controller registers or transfer
state that the interrupt handler also accesses, so they must be called
with bus->lock held. Document this with lockdep_assert_held() in
npcm_i2c_reset(), npcm_i2c_callback() and npcm_i2c_slave_enable() such
that lockdep reports callers that do not hold bus->lock.

Additionally, annotate all functions that require bus->lock with
__must_hold(&bus->lock) such that sparse verifies the locking
statically. Do not annotate the register accessors, npcm_i2c_wr_byte(),
npcm_i2c_master_start(), npcm_i2c_is_master(), npcm_i2c_get_SCL() and
npcm_i2c_get_SDA() since __npcm_i2c_recovery_tgclk() calls these
without holding bus->lock while toggling SCL with controller interrupts
disabled, or npcm_i2c_int_enable() since npcm_i2c_probe_bus() calls it
before the interrupt handler has been registered. Hold bus->lock around
the npcm_i2c_master_stop() call in __npcm_i2c_recovery_tgclk() since
npcm_i2c_master_stop() accesses FIFO registers.

Make the KUnit tests that call these functions directly hold bus->lock,
and let a KUnit test fail if lockdep has disabled itself after having
reported a locking problem. To verify with the KUnit tests that these
functions are called with bus->lock held, also enable
CONFIG_DEBUG_KERNEL and CONFIG_PROVE_LOCKING. Note that
lockdep_assert_held() reports a missing lock with a kernel warning and
does not make a KUnit test fail. Since the KUnit tests call the
interrupt handler from process context, lockdep does not verify the
interrupt safety of bus->lock in these tests.

Google-Bug-Id: 581702595
Tested: KUnit on x86_64 with and without CONFIG_PROVE_LOCKING
Change-Id: I507fd114563ee128ce9d2319b1549e7298d2e512
Signed-off-by: Bart Van Assche <bvanassche@google.com>
1 file changed
tree: 07bf73db255d3d04e67f1ed10ab2ab34943c729d
  1. linux/
  2. .gitmodules