Skip to content

Commit d191152

Browse files
paravmellanoxjgunthorpe
authored andcommitted
IB/counters: Always initialize the port counter object
Port counter objects should be initialized even if alloc_stats is unsupported, otherwise QP bind operations in user space can trigger a NULL pointer deference if they try to bind QP on RDMA device which doesn't support counters. Fixes: f34a55e ("RDMA/core: Get sum value of all counters when perform a sysfs stat read") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Parav Pandit <[email protected]> Reviewed-by: Mark Zhang <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent a379d1c commit d191152

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/infiniband/core/counters.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,17 @@ void rdma_counter_init(struct ib_device *dev)
597597
struct rdma_port_counter *port_counter;
598598
u32 port;
599599

600-
if (!dev->ops.alloc_hw_stats || !dev->port_data)
600+
if (!dev->port_data)
601601
return;
602602

603603
rdma_for_each_port(dev, port) {
604604
port_counter = &dev->port_data[port].port_counter;
605605
port_counter->mode.mode = RDMA_COUNTER_MODE_NONE;
606606
mutex_init(&port_counter->lock);
607607

608+
if (!dev->ops.alloc_hw_stats)
609+
continue;
610+
608611
port_counter->hstats = dev->ops.alloc_hw_stats(dev, port);
609612
if (!port_counter->hstats)
610613
goto fail;
@@ -627,9 +630,6 @@ void rdma_counter_release(struct ib_device *dev)
627630
struct rdma_port_counter *port_counter;
628631
u32 port;
629632

630-
if (!dev->ops.alloc_hw_stats)
631-
return;
632-
633633
rdma_for_each_port(dev, port) {
634634
port_counter = &dev->port_data[port].port_counter;
635635
kfree(port_counter->hstats);

0 commit comments

Comments
 (0)