[PATCH rdma-next 2/3] RDMA/core: Free unpublished port statistics after initial-read failure
From: Leon Romanovsky
Date: Thu Oct 15 2026 - 08:01:33 EST
From: Leon Romanovsky <leonro@xxxxxxxxxx>
An initial port counter read can fail after allocating its statistics
buffer and wrapper. Free these both allocations.
Fixes: 467f432a521a ("RDMA/core: Split port and device counter sysfs attributes")
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
drivers/infiniband/core/sysfs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 69df8b703cbd..4cd861b5d953 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -996,8 +996,8 @@ static int setup_hw_port_stats(struct ib_port *port,
data->stats->num_counters);
if (ret != data->stats->num_counters) {
if (WARN_ON(ret >= 0))
- return -EINVAL;
- return ret;
+ ret = -EINVAL;
+ goto err_free_data;
}
data->stats->timestamp = jiffies;
@@ -1031,6 +1031,11 @@ static int setup_hw_port_stats(struct ib_port *port,
port->hw_stats_data = data;
return 0;
+
+err_free_data:
+ rdma_free_hw_stats_struct(data->stats);
+ kfree(data);
+ return ret;
}
struct rdma_hw_stats *ib_get_hw_stats_port(struct ib_device *ibdev,
--
2.55.0