Module Name:    src
Committed By:   riastradh
Date:           Thu Sep 22 14:44:47 UTC 2022

Modified Files:
        src/sys/dev/pci: ichsmb.c

Log Message:
ichsmb(4): Attach i2c bus only once.

The child could be detached, e.g. with drvctl, and then the bus
rescanned, at which point it would reinitialize a mutex without
destroying it.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/pci/ichsmb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/ichsmb.c
diff -u src/sys/dev/pci/ichsmb.c:1.77 src/sys/dev/pci/ichsmb.c:1.78
--- src/sys/dev/pci/ichsmb.c:1.77	Tue Sep 13 11:47:54 2022
+++ src/sys/dev/pci/ichsmb.c	Thu Sep 22 14:44:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ichsmb.c,v 1.77 2022/09/13 11:47:54 msaitoh Exp $	*/
+/*	$NetBSD: ichsmb.c,v 1.78 2022/09/22 14:44:47 riastradh Exp $	*/
 /*	$OpenBSD: ichiic.c,v 1.44 2020/10/07 11:23:05 jsg Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.77 2022/09/13 11:47:54 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.78 2022/09/22 14:44:47 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -222,6 +222,11 @@ ichsmb_attach(device_t parent, device_t 
 			aprint_normal_dev(self, "polling\n");
 	}
 
+	/* Attach I2C bus */
+	iic_tag_init(&sc->sc_i2c_tag);
+	sc->sc_i2c_tag.ic_cookie = sc;
+	sc->sc_i2c_tag.ic_exec = ichsmb_i2c_exec;
+
 	sc->sc_i2c_device = NULL;
 	ichsmb_rescan(self, NULL, NULL);
 
@@ -238,11 +243,6 @@ ichsmb_rescan(device_t self, const char 
 	if (sc->sc_i2c_device != NULL)
 		return 0;
 
-	/* Attach I2C bus */
-	iic_tag_init(&sc->sc_i2c_tag);
-	sc->sc_i2c_tag.ic_cookie = sc;
-	sc->sc_i2c_tag.ic_exec = ichsmb_i2c_exec;
-
 	memset(&iba, 0, sizeof(iba));
 	iba.iba_tag = &sc->sc_i2c_tag;
 	sc->sc_i2c_device = config_found(self, &iba, iicbus_print, CFARGS_NONE);

Reply via email to