Module Name: src
Committed By: riastradh
Date: Tue Dec 28 12:00:48 UTC 2021
Modified Files:
src/sys/dev/mii: mii_physubr.c
Log Message:
mii(9): Fix callout race between mii_phy_down and mii_phy_detach.
To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/mii/mii_physubr.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/mii/mii_physubr.c
diff -u src/sys/dev/mii/mii_physubr.c:1.96 src/sys/dev/mii/mii_physubr.c:1.97
--- src/sys/dev/mii/mii_physubr.c:1.96 Wed Dec 15 08:28:22 2021
+++ src/sys/dev/mii/mii_physubr.c Tue Dec 28 12:00:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mii_physubr.c,v 1.96 2021/12/15 08:28:22 msaitoh Exp $ */
+/* $NetBSD: mii_physubr.c,v 1.97 2021/12/28 12:00:48 riastradh Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.96 2021/12/15 08:28:22 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.97 2021/12/28 12:00:48 riastradh Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -429,8 +429,20 @@ mii_phy_down(struct mii_softc *sc)
KASSERT(mii_locked(sc->mii_pdata));
if (sc->mii_flags & MIIF_DOINGAUTO) {
- sc->mii_flags &= ~MIIF_DOINGAUTO;
- callout_stop(&sc->mii_nway_ch);
+ /*
+ * Try to stop it.
+ *
+ * - If we stopped it before it expired, callout_stop
+ * returns 0, and it is our responsibility to clear
+ * MIIF_DOINGAUTO.
+ *
+ * - Otherwise, we're too late -- the callout has
+ * already begun, and we must leave MIIF_DOINGAUTO
+ * set so mii_phy_detach will wait for it to
+ * complete.
+ */
+ if (!callout_stop(&sc->mii_nway_ch))
+ sc->mii_flags &= ~MIIF_DOINGAUTO;
}
}