From d74bdcfa89fa45d3a506cddc37b3bf1b76cea0ce Mon Sep 17 00:00:00 2001 From: Leon Romanovsky Date: Sun, 18 Oct 2026 07:59:38 -0400 Subject: [PATCH] RDMA/core: Free unpublished port statistics after initial-read failure 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") Link: https://patch.msgid.link/20261015-ib-core-fixes-v1-2-60f6da3ddec3@nvidia.com Reviewed-by: Kalesh AP Signed-off-by: Leon Romanovsky --- 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,