From a13db3582129c86d3f4e62cc81565d2a67f05ed3 Mon Sep 17 00:00:00 2001 From: Dustin Brown Date: Fri, 12 Jan 2018 13:23:59 -0800 Subject: [PATCH] qcacmn: Hold lock for entire nbuf debug iteration Hold a spinlock for the entire iteration of the nbuf map/unmap hashtable. This prevents invalid list/memory access issues in case of a race with an unmap operation. This also trades list/memory safety for the chance to watchdog bite while printing. Since we are about to panic anyway, the worst case is manually loading the memory dump to inspect the contents of the map/unmap hashtable. Change-Id: Iafc38764d55fc46910051349e4f4b26da33cae51 CRs-Fixed: 2171736 --- qdf/linux/src/qdf_nbuf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/qdf/linux/src/qdf_nbuf.c b/qdf/linux/src/qdf_nbuf.c index 522fe9a2cdcf..0b1d5b413f84 100644 --- a/qdf/linux/src/qdf_nbuf.c +++ b/qdf/linux/src/qdf_nbuf.c @@ -548,15 +548,17 @@ void qdf_nbuf_map_check_for_leaks(void) qdf_err("Nbuf map without unmap events detected!"); qdf_err("------------------------------------------------------------"); + /* Hold the lock for the entire iteration for safe list/meta access. We + * are explicitly preferring the chance to watchdog on the print, over + * the posibility of invalid list/memory access. Since we are going to + * panic anyway, the worst case is loading up the crash dump to find out + * what was in the hash table. + */ qdf_spin_lock_irqsave(&qdf_nbuf_map_lock); hash_for_each(qdf_nbuf_map_ht, bucket, meta, node) { - qdf_spin_unlock_irqrestore(&qdf_nbuf_map_lock); - count++; - qdf_err("0x%pk @ %s:%u", meta->nbuf, kbasename(meta->file), - meta->line); - - qdf_spin_lock_irqsave(&qdf_nbuf_map_lock); + qdf_err("0x%pk @ %s:%u", + meta->nbuf, kbasename(meta->file), meta->line); } qdf_spin_unlock_irqrestore(&qdf_nbuf_map_lock);