RDMA/hns: Fix unnecessary port_num transition in HW stats allocation
authorJunxian Huang <huangjunxian6@hisilicon.com>
Tue, 17 Oct 2023 12:52:38 +0000 (20:52 +0800)
committerLeon Romanovsky <leon@kernel.org>
Thu, 19 Oct 2023 06:49:40 +0000 (09:49 +0300)
The num_ports capability of devices should be compared with the
number of port(i.e. the input param "port_num") but not the port
index(i.e. port_num - 1).

Fixes: 5a87279591a1 ("RDMA/hns: Support hns HW stats")
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Link: https://lore.kernel.org/r/20231017125239.164455-7-huangjunxian6@hisilicon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/hns/hns_roce_main.c

index cb07c303012456dfe44f301f3174308ec84e8832..f62bf8fbe17314cb7f7196fb573a3ff74b67387a 100644 (file)
@@ -547,9 +547,8 @@ static struct rdma_hw_stats *hns_roce_alloc_hw_port_stats(
                                struct ib_device *device, u32 port_num)
 {
        struct hns_roce_dev *hr_dev = to_hr_dev(device);
-       u32 port = port_num - 1;
 
-       if (port > hr_dev->caps.num_ports) {
+       if (port_num > hr_dev->caps.num_ports) {
                ibdev_err(device, "invalid port num.\n");
                return NULL;
        }