Commit 79d0c088 authored by Jubin John's avatar Jubin John Committed by Doug Ledford

staging/rdma/hfi1: Fix memory leaks

Fix 3 memory leaks reported by the LeakCheck tool in the KEDR framework.

The following resources were allocated memory during their respective
initializations but not freed during cleanup:
1. SDMA map elements
2. PIO map elements
3. HW send context to SW index map

This patch fixes the memory leaks by freeing the allocated memory in the
cleanup path.
Reviewed-by: default avatarDean Luick <dean.luick@intel.com>
Reviewed-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Reviewed-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarJubin John <jubin.john@intel.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 409b1462
...@@ -1324,6 +1324,8 @@ static void cleanup_device_data(struct hfi1_devdata *dd) ...@@ -1324,6 +1324,8 @@ static void cleanup_device_data(struct hfi1_devdata *dd)
dd->num_send_contexts = 0; dd->num_send_contexts = 0;
kfree(dd->send_contexts); kfree(dd->send_contexts);
dd->send_contexts = NULL; dd->send_contexts = NULL;
kfree(dd->hw_to_sw);
dd->hw_to_sw = NULL;
kfree(dd->boardname); kfree(dd->boardname);
vfree(dd->events); vfree(dd->events);
vfree(dd->status); vfree(dd->status);
......
...@@ -1881,7 +1881,7 @@ void free_pio_map(struct hfi1_devdata *dd) ...@@ -1881,7 +1881,7 @@ void free_pio_map(struct hfi1_devdata *dd)
/* Free PIO map if allocated */ /* Free PIO map if allocated */
if (rcu_access_pointer(dd->pio_map)) { if (rcu_access_pointer(dd->pio_map)) {
spin_lock_irq(&dd->pio_map_lock); spin_lock_irq(&dd->pio_map_lock);
kfree(rcu_access_pointer(dd->pio_map)); pio_map_free(rcu_access_pointer(dd->pio_map));
RCU_INIT_POINTER(dd->pio_map, NULL); RCU_INIT_POINTER(dd->pio_map, NULL);
spin_unlock_irq(&dd->pio_map_lock); spin_unlock_irq(&dd->pio_map_lock);
synchronize_rcu(); synchronize_rcu();
......
...@@ -966,7 +966,7 @@ static void sdma_clean(struct hfi1_devdata *dd, size_t num_engines) ...@@ -966,7 +966,7 @@ static void sdma_clean(struct hfi1_devdata *dd, size_t num_engines)
sde->tx_ring = NULL; sde->tx_ring = NULL;
} }
spin_lock_irq(&dd->sde_map_lock); spin_lock_irq(&dd->sde_map_lock);
kfree(rcu_access_pointer(dd->sdma_map)); sdma_map_free(rcu_access_pointer(dd->sdma_map));
RCU_INIT_POINTER(dd->sdma_map, NULL); RCU_INIT_POINTER(dd->sdma_map, NULL);
spin_unlock_irq(&dd->sde_map_lock); spin_unlock_irq(&dd->sde_map_lock);
synchronize_rcu(); synchronize_rcu();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment