Re: [PATCH] RDMA/core: Complete exception handling in add_port()

From: Markus Elfring
Date: Mon May 25 2020 - 08:55:03 EST


> In function add_port(), pointer p is not released in error paths.

1. I would prefer to describe that an ib_port data structure was not released
in some error cases.
How relevant can its size be here?


> Fix this issue by adding a kfree(p) into the end of error path.

2. I suggest to improve also this change description.

3. I find an other subject more appropriate.


â
> +++ b/drivers/infiniband/core/sysfs.c
> @@ -1202,6 +1202,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
>
> err_put:
> kobject_put(&p->kobj);
> + kfree(p);
> return ret;
> }

4. I recommend to add also the label âfree_portâ before the missed function call.

Another source code place should be accordingly adjusted then.

ret = kobject_init_and_add(&p->kobj, &port_type,
coredev->ports_kobj,
"%d", port_num);
- if (ret) {
- kfree(p);
- return ret;
- }
+ if (ret)
+ goto free_port;


5. Will a similar adjustment be needed for the data structure member âgid_attr_groupâ
according to the desired complete exception handling?

Regards,
Markus