qcacmn: Return error on nbuf map alloc failure

When nbuf map/unmap tracking is enabled, a small metadata structure is
allocated to keep the tracking information. In cases where this
allocation fails during the map operation, return an error status
instead of mapping the nbuf. This prevents a false positive
unmap-never-mapped panic when the nbuf is unmapped.

Change-Id: Id01c1f61165a0beff4edd6cc6a0a2fc5f64d9b04
CRs-Fixed: 2167082
diff --git a/qdf/linux/src/qdf_nbuf.c b/qdf/linux/src/qdf_nbuf.c
index 9a485c1..dbfe669 100644
--- a/qdf/linux/src/qdf_nbuf.c
+++ b/qdf/linux/src/qdf_nbuf.c
@@ -537,7 +537,7 @@
 	return NULL;
 }
 
-static void
+static QDF_STATUS
 qdf_nbuf_track_map(qdf_nbuf_t nbuf, const char *file, uint32_t line)
 {
 	struct qdf_nbuf_map_metadata *meta;
@@ -545,7 +545,7 @@
 	QDF_BUG(nbuf);
 	if (!nbuf) {
 		qdf_err("Cannot map null nbuf");
-		return;
+		return QDF_STATUS_E_INVAL;
 	}
 
 	qdf_spin_lock_irqsave(&qdf_nbuf_map_lock);
@@ -558,7 +558,7 @@
 	meta = qdf_mem_malloc(sizeof(*meta));
 	if (!meta) {
 		qdf_err("Failed to allocate nbuf map tracking metadata");
-		return;
+		return QDF_STATUS_E_NOMEM;
 	}
 
 	meta->nbuf = nbuf;
@@ -568,6 +568,8 @@
 	qdf_spin_lock_irqsave(&qdf_nbuf_map_lock);
 	hash_add(qdf_nbuf_map_ht, &meta->node, (size_t)nbuf);
 	qdf_spin_unlock_irqrestore(&qdf_nbuf_map_lock);
+
+	return QDF_STATUS_SUCCESS;
 }
 
 static void
@@ -600,7 +602,11 @@
 			      const char *file,
 			      uint32_t line)
 {
-	qdf_nbuf_track_map(buf, file, line);
+	QDF_STATUS status;
+
+	status = qdf_nbuf_track_map(buf, file, line);
+	if (QDF_IS_STATUS_ERROR(status))
+		return status;
 
 	return __qdf_nbuf_map(osdev, buf, dir);
 }
@@ -621,7 +627,11 @@
 				     const char *file,
 				     uint32_t line)
 {
-	qdf_nbuf_track_map(buf, file, line);
+	QDF_STATUS status;
+
+	status = qdf_nbuf_track_map(buf, file, line);
+	if (QDF_IS_STATUS_ERROR(status))
+		return status;
 
 	return __qdf_nbuf_map_single(osdev, buf, dir);
 }
@@ -643,7 +653,11 @@
 				     const char *file,
 				     uint32_t line)
 {
-	qdf_nbuf_track_map(buf, file, line);
+	QDF_STATUS status;
+
+	status = qdf_nbuf_track_map(buf, file, line);
+	if (QDF_IS_STATUS_ERROR(status))
+		return status;
 
 	return __qdf_nbuf_map_nbytes(osdev, buf, dir, nbytes);
 }
@@ -666,7 +680,11 @@
 					    const char *file,
 					    uint32_t line)
 {
-	qdf_nbuf_track_map(buf, file, line);
+	QDF_STATUS status;
+
+	status = qdf_nbuf_track_map(buf, file, line);
+	if (QDF_IS_STATUS_ERROR(status))
+		return status;
 
 	return __qdf_nbuf_map_nbytes_single(osdev, buf, dir, nbytes);
 }