diff --git a/hostapd/driver_i.h b/hostapd/driver_i.h
index 64e8c90d0..aa280f79c 100644
--- a/hostapd/driver_i.h
+++ b/hostapd/driver_i.h
@@ -18,14 +18,6 @@
 #include "drivers/driver.h"
 #include "ap/config.h"
 
-static inline void
-hostapd_driver_deinit(struct hostapd_data *hapd)
-{
-	if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
-		return;
-	hapd->driver->hapd_deinit(hapd->drv_priv);
-}
-
 static inline int
 hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
 {
diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c
index fd8eb6df0..588b02b63 100644
--- a/hostapd/hostapd.c
+++ b/hostapd/hostapd.c
@@ -819,8 +819,6 @@ void hostapd_interface_deinit(struct hostapd_iface *iface)
 		hostapd_free_stas(hapd);
 		hostapd_flush_old_stations(hapd);
 		hostapd_cleanup(hapd);
-		if (j == iface->num_bss - 1 && hapd->driver)
-			hostapd_driver_deinit(hapd);
 	}
 	for (j = 0; j < iface->num_bss; j++)
 		os_free(iface->bss[j]);
diff --git a/hostapd/main.c b/hostapd/main.c
index 0b9a2d589..79e2969e0 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -291,7 +291,13 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
 
 	if (hostapd_driver_init(iface) ||
 	    hostapd_setup_interface(iface)) {
+		const struct wpa_driver_ops *driver;
+		void *drv_priv;
+		driver = iface->bss[0]->driver;
+		drv_priv = iface->bss[0]->drv_priv;
 		hostapd_interface_deinit(iface);
+		if (driver && driver->hapd_deinit)
+			driver->hapd_deinit(drv_priv);
 		return NULL;
 	}
 
@@ -532,8 +538,16 @@ int main(int argc, char *argv[])
 
  out:
 	/* Deinitialize all interfaces */
-	for (i = 0; i < interfaces.count; i++)
-		hostapd_interface_deinit(interfaces.iface[i]);
+	for (i = 0; i < interfaces.count; i++) {
+		struct hostapd_iface *iface = interfaces.iface[i];
+		const struct wpa_driver_ops *driver;
+		void *drv_priv;
+		driver = iface->bss[0]->driver;
+		drv_priv = iface->bss[0]->drv_priv;
+		hostapd_interface_deinit(iface);
+		if (driver && driver->hapd_deinit)
+			driver->hapd_deinit(drv_priv);
+	}
 	os_free(interfaces.iface);
 
 	hostapd_global_deinit(pid_file);
diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c
index 2fc875cd5..ac7e5db53 100644
--- a/wpa_supplicant/ap.c
+++ b/wpa_supplicant/ap.c
@@ -519,11 +519,18 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
 
 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
 {
+	const struct wpa_driver_ops *driver;
+	void *drv_priv;
+
 	if (wpa_s->ap_iface == NULL)
 		return;
 
+	driver = wpa_s->ap_iface->bss[0]->driver;
+	drv_priv = wpa_s->ap_iface->bss[0]->drv_priv;
 	hostapd_interface_deinit(wpa_s->ap_iface);
 	wpa_s->ap_iface = NULL;
+	if (driver && driver->hapd_deinit)
+		driver->hapd_deinit(drv_priv);
 }