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: f34a55e497 ("RDMA/core: Get sum value of all counters when perform a sysfs stat read")
Link: https://lore.kernel.org/r/20190723065733.4899-11-leon@kernel.org
Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Mark Zhang <markz@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
committed by
Jason Gunthorpe
parent
a379d1ce32
commit
d191152f43
@@ -597,7 +597,7 @@ void rdma_counter_init(struct ib_device *dev)
|
|||||||
struct rdma_port_counter *port_counter;
|
struct rdma_port_counter *port_counter;
|
||||||
u32 port;
|
u32 port;
|
||||||
|
|
||||||
if (!dev->ops.alloc_hw_stats || !dev->port_data)
|
if (!dev->port_data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rdma_for_each_port(dev, port) {
|
rdma_for_each_port(dev, port) {
|
||||||
@@ -605,6 +605,9 @@ void rdma_counter_init(struct ib_device *dev)
|
|||||||
port_counter->mode.mode = RDMA_COUNTER_MODE_NONE;
|
port_counter->mode.mode = RDMA_COUNTER_MODE_NONE;
|
||||||
mutex_init(&port_counter->lock);
|
mutex_init(&port_counter->lock);
|
||||||
|
|
||||||
|
if (!dev->ops.alloc_hw_stats)
|
||||||
|
continue;
|
||||||
|
|
||||||
port_counter->hstats = dev->ops.alloc_hw_stats(dev, port);
|
port_counter->hstats = dev->ops.alloc_hw_stats(dev, port);
|
||||||
if (!port_counter->hstats)
|
if (!port_counter->hstats)
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -627,9 +630,6 @@ void rdma_counter_release(struct ib_device *dev)
|
|||||||
struct rdma_port_counter *port_counter;
|
struct rdma_port_counter *port_counter;
|
||||||
u32 port;
|
u32 port;
|
||||||
|
|
||||||
if (!dev->ops.alloc_hw_stats)
|
|
||||||
return;
|
|
||||||
|
|
||||||
rdma_for_each_port(dev, port) {
|
rdma_for_each_port(dev, port) {
|
||||||
port_counter = &dev->port_data[port].port_counter;
|
port_counter = &dev->port_data[port].port_counter;
|
||||||
kfree(port_counter->hstats);
|
kfree(port_counter->hstats);
|
||||||
|
|||||||
Reference in New Issue
Block a user