From 5819e29cbb6ea70d03bfe2c2394f7011bea8243b Mon Sep 17 00:00:00 2001 From: Dustin Brown Date: Thu, 4 Jan 2018 11:06:23 -0800 Subject: [PATCH] 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 --- qdf/linux/src/qdf_nbuf.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/qdf/linux/src/qdf_nbuf.c b/qdf/linux/src/qdf_nbuf.c index 9a485c1de847..dbfe669fccda 100644 --- a/qdf/linux/src/qdf_nbuf.c +++ b/qdf/linux/src/qdf_nbuf.c @@ -537,7 +537,7 @@ static struct qdf_nbuf_map_metadata *qdf_nbuf_meta_get(qdf_nbuf_t nbuf) 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_nbuf_track_map(qdf_nbuf_t nbuf, const char *file, uint32_t line) 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 @@ qdf_nbuf_track_map(qdf_nbuf_t nbuf, const char *file, uint32_t line) 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_nbuf_track_map(qdf_nbuf_t nbuf, const char *file, uint32_t line) 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 @@ QDF_STATUS qdf_nbuf_map_debug(qdf_device_t osdev, 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 @@ QDF_STATUS qdf_nbuf_map_single_debug(qdf_device_t osdev, 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 @@ QDF_STATUS qdf_nbuf_map_nbytes_debug(qdf_device_t osdev, 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 @@ QDF_STATUS qdf_nbuf_map_nbytes_single_debug(qdf_device_t osdev, 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); }