Commit a7d0e959 authored by Dan Carpenter's avatar Dan Carpenter Committed by Doug Ledford

IB/cma: allocating too much memory in make_cma_ports()

The issue here is that there is a cut and paste bug.  When we allocate
cma_dev_group->default_ports_group we use "sizeof(*cma_dev_group->ports)"
instead of "sizeof(*cma_dev_group->default_ports_group)".

We're bumping up against the 80 character limit so I introduced a new
local pointer "ports_group" to get around that.

Fixes: 045959db ('IB/cma: Add configfs for rdma_cm')
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Acked-by: default avatarMatan Barak <matanb@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent bc1251e6
...@@ -158,6 +158,7 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group, ...@@ -158,6 +158,7 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
unsigned int i; unsigned int i;
unsigned int ports_num; unsigned int ports_num;
struct cma_dev_port_group *ports; struct cma_dev_port_group *ports;
struct config_group **ports_group;
int err; int err;
ibdev = cma_get_ib_dev(cma_dev); ibdev = cma_get_ib_dev(cma_dev);
...@@ -168,12 +169,9 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group, ...@@ -168,12 +169,9 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
ports_num = ibdev->phys_port_cnt; ports_num = ibdev->phys_port_cnt;
ports = kcalloc(ports_num, sizeof(*cma_dev_group->ports), ports = kcalloc(ports_num, sizeof(*cma_dev_group->ports),
GFP_KERNEL); GFP_KERNEL);
ports_group = kcalloc(ports_num + 1, sizeof(*ports_group), GFP_KERNEL);
cma_dev_group->default_ports_group = kcalloc(ports_num + 1, if (!ports || !ports_group) {
sizeof(*cma_dev_group->ports),
GFP_KERNEL);
if (!ports || !cma_dev_group->default_ports_group) {
err = -ENOMEM; err = -ENOMEM;
goto free; goto free;
} }
...@@ -187,15 +185,16 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group, ...@@ -187,15 +185,16 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
config_group_init_type_name(&ports[i].group, config_group_init_type_name(&ports[i].group,
port_str, port_str,
&cma_port_group_type); &cma_port_group_type);
cma_dev_group->default_ports_group[i] = &ports[i].group; ports_group[i] = &ports[i].group;
} }
cma_dev_group->default_ports_group[i] = NULL; ports_group[i] = NULL;
cma_dev_group->default_ports_group = ports_group;
cma_dev_group->ports = ports; cma_dev_group->ports = ports;
return 0; return 0;
free: free:
kfree(ports); kfree(ports);
kfree(cma_dev_group->default_ports_group); kfree(ports_group);
cma_dev_group->ports = NULL; cma_dev_group->ports = NULL;
cma_dev_group->default_ports_group = NULL; cma_dev_group->default_ports_group = NULL;
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment