vf_i2c: Don't hold a mutex across bus_generic_detach

This was also leaking the lock if bus_generic_detach failed.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47221

(cherry picked from commit 13a1dbfed57b167a6dc4d68b60115eb0e070b9b6)
This commit is contained in:
John Baldwin 2024-10-31 15:49:41 -04:00
parent 82ee73e713
commit e09c819e6a

View file

@ -207,13 +207,6 @@ i2c_detach(device_t dev)
sc = device_get_softc(dev);
vf_i2c_dbg(sc, "i2c detach\n");
mtx_lock(&sc->mutex);
if (sc->freq == 0) {
vf_i2c_dbg(sc, "Writing 0x00 to clock divider register\n");
WRITE1(sc, I2C_IBFD, 0x00);
}
error = bus_generic_detach(dev);
if (error != 0) {
device_printf(dev, "cannot detach child devices.\n");
@ -226,6 +219,13 @@ i2c_detach(device_t dev)
return (error);
}
mtx_lock(&sc->mutex);
if (sc->freq == 0) {
vf_i2c_dbg(sc, "Writing 0x00 to clock divider register\n");
WRITE1(sc, I2C_IBFD, 0x00);
}
bus_release_resources(dev, i2c_spec, sc->res);
mtx_unlock(&sc->mutex);