diff mbox

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

Message ID 20160112092921.GB29804@mwanda (mailing list archive)
State Accepted
Headers show

Commit Message

Dan Carpenter Jan. 12, 2016, 9:29 a.m. UTC
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: 045959db65c6 ('IB/cma: Add configfs for rdma_cm')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Not tested.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Matan Barak Jan. 12, 2016, 1:08 p.m. UTC | #1
On Tue, Jan 12, 2016 at 11:29 AM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> 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: 045959db65c6 ('IB/cma: Add configfs for rdma_cm')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Not tested.
>
> diff --git a/drivers/infiniband/core/cma_configfs.c b/drivers/infiniband/core/cma_configfs.c
> index bd1d640..18b112a 100644
> --- a/drivers/infiniband/core/cma_configfs.c
> +++ b/drivers/infiniband/core/cma_configfs.c
> @@ -158,6 +158,7 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
>         unsigned int i;
>         unsigned int ports_num;
>         struct cma_dev_port_group *ports;
> +       struct config_group **ports_group;
>         int err;
>
>         ibdev = cma_get_ib_dev(cma_dev);
> @@ -168,12 +169,9 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
>         ports_num = ibdev->phys_port_cnt;
>         ports = kcalloc(ports_num, sizeof(*cma_dev_group->ports),
>                         GFP_KERNEL);
> +       ports_group = kcalloc(ports_num + 1, sizeof(*ports_group), GFP_KERNEL);
>
> -       cma_dev_group->default_ports_group = kcalloc(ports_num + 1,
> -                                                    sizeof(*cma_dev_group->ports),
> -                                                    GFP_KERNEL);
> -
> -       if (!ports || !cma_dev_group->default_ports_group) {
> +       if (!ports || !ports_group) {
>                 err = -ENOMEM;
>                 goto free;
>         }
> @@ -187,15 +185,16 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
>                 config_group_init_type_name(&ports[i].group,
>                                             port_str,
>                                             &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;
>
>         return 0;
>  free:
>         kfree(ports);
> -       kfree(cma_dev_group->default_ports_group);
> +       kfree(ports_group);
>         cma_dev_group->ports = NULL;
>         cma_dev_group->default_ports_group = NULL;
>         return err;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Hi,

This is already fixed in [1].
Anyway, I'm fine with either one of them.

Acked-by: Matan Barak <matanb@mellanox.com>

Regards,
Matan

[1] http://www.spinics.net/lists/linux-rdma/msg32152.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Doug Ledford Jan. 19, 2016, 8:59 p.m. UTC | #2
On 01/12/2016 08:08 AM, Matan Barak wrote:
> On Tue, Jan 12, 2016 at 11:29 AM, Dan Carpenter
> <dan.carpenter@oracle.com> wrote:
>> 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: 045959db65c6 ('IB/cma: Add configfs for rdma_cm')
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>> ---
>> Not tested.
>>
>> diff --git a/drivers/infiniband/core/cma_configfs.c b/drivers/infiniband/core/cma_configfs.c
>> index bd1d640..18b112a 100644
>> --- a/drivers/infiniband/core/cma_configfs.c
>> +++ b/drivers/infiniband/core/cma_configfs.c
>> @@ -158,6 +158,7 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
>>         unsigned int i;
>>         unsigned int ports_num;
>>         struct cma_dev_port_group *ports;
>> +       struct config_group **ports_group;
>>         int err;
>>
>>         ibdev = cma_get_ib_dev(cma_dev);
>> @@ -168,12 +169,9 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
>>         ports_num = ibdev->phys_port_cnt;
>>         ports = kcalloc(ports_num, sizeof(*cma_dev_group->ports),
>>                         GFP_KERNEL);
>> +       ports_group = kcalloc(ports_num + 1, sizeof(*ports_group), GFP_KERNEL);
>>
>> -       cma_dev_group->default_ports_group = kcalloc(ports_num + 1,
>> -                                                    sizeof(*cma_dev_group->ports),
>> -                                                    GFP_KERNEL);
>> -
>> -       if (!ports || !cma_dev_group->default_ports_group) {
>> +       if (!ports || !ports_group) {
>>                 err = -ENOMEM;
>>                 goto free;
>>         }
>> @@ -187,15 +185,16 @@ static int make_cma_ports(struct cma_dev_group *cma_dev_group,
>>                 config_group_init_type_name(&ports[i].group,
>>                                             port_str,
>>                                             &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;
>>
>>         return 0;
>>  free:
>>         kfree(ports);
>> -       kfree(cma_dev_group->default_ports_group);
>> +       kfree(ports_group);
>>         cma_dev_group->ports = NULL;
>>         cma_dev_group->default_ports_group = NULL;
>>         return err;
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> Hi,
> 
> This is already fixed in [1].
> Anyway, I'm fine with either one of them.
> 
> Acked-by: Matan Barak <matanb@mellanox.com>
> 
> Regards,
> Matan
> 
> [1] http://www.spinics.net/lists/linux-rdma/msg32152.html
> 

Thanks, applied.
diff mbox

Patch

diff --git a/drivers/infiniband/core/cma_configfs.c b/drivers/infiniband/core/cma_configfs.c
index bd1d640..18b112a 100644
--- a/drivers/infiniband/core/cma_configfs.c
+++ b/drivers/infiniband/core/cma_configfs.c
@@ -158,6 +158,7 @@  static int make_cma_ports(struct cma_dev_group *cma_dev_group,
 	unsigned int i;
 	unsigned int ports_num;
 	struct cma_dev_port_group *ports;
+	struct config_group **ports_group;
 	int err;
 
 	ibdev = cma_get_ib_dev(cma_dev);
@@ -168,12 +169,9 @@  static int make_cma_ports(struct cma_dev_group *cma_dev_group,
 	ports_num = ibdev->phys_port_cnt;
 	ports = kcalloc(ports_num, sizeof(*cma_dev_group->ports),
 			GFP_KERNEL);
+	ports_group = kcalloc(ports_num + 1, sizeof(*ports_group), GFP_KERNEL);
 
-	cma_dev_group->default_ports_group = kcalloc(ports_num + 1,
-						     sizeof(*cma_dev_group->ports),
-						     GFP_KERNEL);
-
-	if (!ports || !cma_dev_group->default_ports_group) {
+	if (!ports || !ports_group) {
 		err = -ENOMEM;
 		goto free;
 	}
@@ -187,15 +185,16 @@  static int make_cma_ports(struct cma_dev_group *cma_dev_group,
 		config_group_init_type_name(&ports[i].group,
 					    port_str,
 					    &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;
 
 	return 0;
 free:
 	kfree(ports);
-	kfree(cma_dev_group->default_ports_group);
+	kfree(ports_group);
 	cma_dev_group->ports = NULL;
 	cma_dev_group->default_ports_group = NULL;
 	return err;