net: mctp: i3c: serialize probe with bus removal

mctp_i3c_probe() drops busdevs_lock after finding the matching bus. A
concurrent I3C_NOTIFY_BUS_REMOVE can then unregister and free the bus
netdev before probe passes its private data to mctp_i3c_add_device().
The latter consequently adds a list node through a freed mbus pointer.

Keep busdevs_lock held until the device has been added. This also
satisfies the __must_hold annotation on mctp_i3c_add_device().

Fixes: c8755b29b5 ("mctp i3c: MCTP I3C driver")
Signed-off-by: XingWang Xiang <v3rdant.xiang@gmail.com>
Acked-by: Matt Johnston <matt@codeconstruct.com.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
XingWang Xiang 2026-09-02 15:01:18 +09:00 committed by David S. Miller
parent 80dd7e754b
commit 2b4707a149

View File

@ -288,6 +288,7 @@ __must_hold(&busdevs_lock)
static int mctp_i3c_probe(struct i3c_device *i3c)
{
struct mctp_i3c_bus *b = NULL, *mbus = NULL;
int rc;
/* Look for a known bus */
mutex_lock(&busdevs_lock);
@ -296,14 +297,16 @@ static int mctp_i3c_probe(struct i3c_device *i3c)
mbus = b;
break;
}
mutex_unlock(&busdevs_lock);
if (!mbus) {
/* probably no "mctp-controller" property on the i3c bus */
return -ENODEV;
rc = -ENODEV;
} else {
rc = mctp_i3c_add_device(mbus, i3c);
}
mutex_unlock(&busdevs_lock);
return mctp_i3c_add_device(mbus, i3c);
return rc;
}
static void mctp_i3c_remove_device(struct mctp_i3c_device *mi)