⬢ DragonFlyBSD Kernel Audit
DF-4374 / fix.diff
← back to finding ↓ download raw
--- a/sys/dev/netif/ath/ath/if_ath_sysctl.c
+++ b/sys/dev/netif/ath/ath/if_ath_sysctl.c
@@ -254,10 +254,13 @@
 	int error;
 
 	ATH_LOCK(sc);
-	ath_power_set_power_state(sc, HAL_PM_AWAKE);
-	ATH_UNLOCK(sc);
-
+	if (sc->sc_invalid) {	/* detaching: no safe HAL access */
+		ATH_UNLOCK(sc);
+		return (ENXIO);
+	}
+	ath_power_set_power_state(sc, HAL_PM_AWAKE);
 	txantenna = ath_hal_getantennaswitch(sc->sc_ah);
+	ATH_UNLOCK(sc);
 
 	error = sysctl_handle_int(oidp, &txantenna, 0, req);
 	if (!error && req->newptr) {
@@ -266,6 +269,12 @@
 			error = EINVAL;
 			goto finish;
 		}
+		ATH_LOCK(sc);
+		if (sc->sc_invalid) {	/* detaching: no safe HAL access */
+			ATH_UNLOCK(sc);
+			return (ENXIO);
+		}
+		ath_power_set_power_state(sc, HAL_PM_AWAKE);
 		ath_hal_setantennaswitch(sc->sc_ah, txantenna);
 		/*
 		 * NB: with the switch locked this isn't meaningful,