i2c: img-scb: BUG: spinlock bad magic in img_i2c_isr() on early IRQ
From: Jaeyoung Chung
Date: Wed Jun 10 2026 - 07:44:39 EST
Hi,
img_i2c_probe() in drivers/i2c/busses/i2c-img-scb.c registers the
interrupt handler with devm_request_irq() before it initializes
i2c->lock with spin_lock_init(). If an interrupt arrives before
spin_lock_init() runs, the handler acquires an uninitialized spinlock,
which triggers a kernel warning.
The probe path, in img_i2c_probe():
i2c = devm_kzalloc(&pdev->dev, ...); /* i2c->lock zeroed */
...
ret = devm_request_irq(&pdev->dev, irq, img_i2c_isr, 0,
pdev->name, i2c); /* register handler */
...
spin_lock_init(&i2c->lock); /* initialize lock */
The interrupt handler, img_i2c_isr(), takes the spinlock.
If the device raises an interrupt before spin_lock_init() runs, the
handler acquires i2c->lock while it is still uninitialized, which
triggers "BUG: spinlock bad magic" when CONFIG_DEBUG_SPINLOCK is
enabled.
Suggested fix: move spin_lock_init(&i2c->lock) above devm_request_irq(),
so the lock is valid before the handler can run.
Reported-by: Sangyun Kim <sangyun.kim@xxxxxxxxx>
Reported-by: Kyungwook Boo <bookyungwook@xxxxxxxxx>
Thanks,
Jaeyoung Chung