Skip to contentSkip to conversation

RDMA/core: Complete exception handling in add_port()

PATCH Markus Elfring 1 participant 1 message May 25, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 1 line

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?

Quoted 1 line

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.

…

Review static int add_port(struct ib_core_device *coredev, int port_num) · line 1207

Quoted 8 lines

+++ b/drivers/infiniband/core/sysfs.c

(quoted diff) +1 -0
@@ -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