git: e09c819e6a4c - stable/14 - vf_i2c: Don't hold a mutex across bus_generic_detach

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Sun, 01 Dec 2024 04:57:07 UTC
The branch stable/14 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=e09c819e6a4ceb6babc51057e12afa792569342f

commit e09c819e6a4ceb6babc51057e12afa792569342f
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-10-31 19:49:41 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-12-01 02:46:05 +0000

    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)
---
 sys/dev/iicbus/controller/vybrid/vf_i2c.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sys/dev/iicbus/controller/vybrid/vf_i2c.c b/sys/dev/iicbus/controller/vybrid/vf_i2c.c
index d3c3664af78c..e034ab278f40 100644
--- a/sys/dev/iicbus/controller/vybrid/vf_i2c.c
+++ b/sys/dev/iicbus/controller/vybrid/vf_i2c.c
@@ -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);