[v3,27/33] net/ena/hal: modify customer metrics memory management
Checks
Commit Message
From: Shai Brandes <shaibran@amazon.com>
1. Set buffer length to zero in case memory allocation failed
and after memory is released.
2. The driver checks buffer_virt_addr for customer allocation
success. In case the allocation fails, buffer_virt_addr
may not necessarily be NULL.
Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Amit Bernstein <amitbern@amazon.com>
---
drivers/net/ena/hal/ena_com.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
@@ -3233,13 +3233,17 @@ int ena_com_allocate_customer_metrics_buffer(struct ena_com_dev *ena_dev)
struct ena_customer_metrics *customer_metrics = &ena_dev->customer_metrics;
customer_metrics->buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE;
+ customer_metrics->buffer_virt_addr = NULL;
+
ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev,
customer_metrics->buffer_len,
customer_metrics->buffer_virt_addr,
customer_metrics->buffer_dma_addr,
customer_metrics->buffer_dma_handle);
- if (unlikely(!customer_metrics->buffer_virt_addr))
+ if (unlikely(!customer_metrics->buffer_virt_addr)) {
+ customer_metrics->buffer_len = 0;
return ENA_COM_NO_MEM;
+ }
return 0;
}
@@ -3283,6 +3287,7 @@ void ena_com_delete_customer_metrics_buffer(struct ena_com_dev *ena_dev)
customer_metrics->buffer_dma_addr,
customer_metrics->buffer_dma_handle);
customer_metrics->buffer_virt_addr = NULL;
+ customer_metrics->buffer_len = 0;
}
}