This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Error in nrf_cloud_agps_process function of SDK v1.6.0

Hello,

in subsys/net/lib/nrf_cloud/src/nrf_cloud_agps.c, in function int nrf_cloud_agps_process() there is an error - we are taking semaphor and then do check for validity of data and if data is invalid simply return, so the semaphor stays locked therefore on next call of this function can lead to deadlock. My fix is below:

@@ -673,39 +673,38 @@ static size_t get_next_agps_element(struct nrf_cloud_apgs_element *element,
 
 int nrf_cloud_agps_process(const char *buf, size_t buf_len, const int *socket)
 {
 	int err;
 	struct nrf_cloud_apgs_element element = {0};
 	struct nrf_cloud_agps_system_time sys_time = {0};
 	uint32_t sv_mask = 0;
 	size_t parsed_len = 0;
 	uint8_t version;
 
-
-	err = k_sem_take(&agps_injection_active, K_FOREVER);
-	if (err) {
-		LOG_ERR("A-GPS injection already active.");
-		return err;
-	}
-	LOG_DBG("A-GPS_injection_active LOCKED");
-
 	version = buf[NRF_CLOUD_AGPS_BIN_SCHEMA_VERSION_INDEX];
 	parsed_len += NRF_CLOUD_AGPS_BIN_SCHEMA_VERSION_SIZE;
 
 	if (version != NRF_CLOUD_AGPS_BIN_SCHEMA_VERSION) {
 		LOG_ERR("Cannot parse schema version: %d", version);
 		return -EBADMSG;
 	}
 
 	LOG_DBG("Received AGPS data. Schema version: %d, length: %d",
 		version, buf_len);
 
+	err = k_sem_take(&agps_injection_active, K_FOREVER);
+	if (err) {
+		LOG_ERR("A-GPS injection already active.");
+		return err;
+	}
+	LOG_DBG("A-GPS_injection_active LOCKED");
+
 	if (socket) {
 		LOG_DBG("Using user-provided socket, fd %d", fd);

Parents Reply Children
No Data
Related