p2p: check p2p instance in all asynchronized callbacks

If cancelConnect is not called, the scan retry callback
would be called several times. If P2P is disabled in this period,
these asynchronized callbacks would access de-initialized p2p
instance and result in native crash.

Bug: 141773120
Test: atest VtsHalWifiSupplicantP2pV1_2TargetTest
Change-Id: Ifc1b397a6c48044b3ef10f110cd89186e2e27a8d
diff --git a/wpa_supplicant/hidl/1.2/p2p_iface.cpp b/wpa_supplicant/hidl/1.2/p2p_iface.cpp
index 0a6b657..fd9ce0d 100644
--- a/wpa_supplicant/hidl/1.2/p2p_iface.cpp
+++ b/wpa_supplicant/hidl/1.2/p2p_iface.cpp
@@ -225,7 +225,7 @@
 	size_t ielen;
 	unsigned int bands;
 
-	if (!wpa_s->global->p2p) {
+	if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
 		wpa_printf(MSG_ERROR,
 		    "P2P: P2P interface is gone, cancel join scan");
 		return -ENXIO;
@@ -1634,7 +1634,7 @@
 	int vht = wpa_s->conf->p2p_go_vht;
 	int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
 
-	if (wpa_s->global->p2p == NULL) {
+	if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
 		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
 	}
 
@@ -1691,6 +1691,9 @@
 
 	pending_join_scan_callback =
 	    [wpa_s, ssid, freq]() {
+		if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
+			return;
+		}
 		int ret = joinScanReq(wpa_s, ssid, freq);
 		// for BUSY case, the scan might be occupied by WiFi.
 		// Do not give up immediately, but try again later.
@@ -1707,7 +1710,7 @@
 	};
 
 	pending_scan_res_join_callback = [wpa_s, ssid, passphrase, peer_address, this]() {
-		if (wpa_s->global->p2p_disabled) {
+		if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
 			return;
 		}