diff mbox series

[netifd] bridge: always insert new member if allocated on hotplug add

Message ID 20230624123412.856-1-ansuelsmth@gmail.com
State Accepted
Delegated to: Ansuel Smith
Headers show
Series [netifd] bridge: always insert new member if allocated on hotplug add | expand

Commit Message

Christian Marangi June 24, 2023, 12:34 p.m. UTC
Fix Coverity Defect 1532481 reporting a Resource leak when
!bm->node.avl.key is false in bridge_hotplug_add.

While this situation is almost impossible, code can be refactored to
mute the defect and make it clear that we insert only when a new member
is allocated.

Fixes: edf3aced9f9a ("bridge: add support for adding vlan ranges via hotplug")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 bridge.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Felix Fietkau June 24, 2023, 6:54 p.m. UTC | #1
On 24.06.23 14:34, Christian Marangi wrote:
> Fix Coverity Defect 1532481 reporting a Resource leak when
> !bm->node.avl.key is false in bridge_hotplug_add.
> 
> While this situation is almost impossible, code can be refactored to
> mute the defect and make it clear that we insert only when a new member
> is allocated.
> 
> Fixes: edf3aced9f9a ("bridge: add support for adding vlan ranges via hotplug")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Applied with some changes to make it clear that this is a false positive 
report.

Thanks,

- Felix
diff mbox series

Patch

diff --git a/bridge.c b/bridge.c
index 471c651..202b69b 100644
--- a/bridge.c
+++ b/bridge.c
@@ -930,12 +930,15 @@  bridge_hotplug_add(struct device *dev, struct device *member, struct blob_attr *
 {
 	struct bridge_state *bst = container_of(dev, struct bridge_state, dev);
 	struct bridge_member *bm;
+	bool to_insert = false;
 
 	bm = vlist_find(&bst->members, member->ifname, bm, node);
-	if (!bm)
+	if (!bm) {
+	    to_insert = true;
 	    bm = bridge_alloc_member(bst, member->ifname, member, true);
+	}
 	bridge_hotplug_set_member_vlans(bst, vlan, member->ifname, bm, true);
-	if (!bm->node.avl.key)
+	if (to_insert)
 		bridge_insert_member(bm, member->ifname);
 
 	return 0;