Skip to content

Commit a616752

Browse files
Chen AotianStefan-Schmidt
authored andcommitted
ieee802154: hwsim: Fix possible memory leaks
After replacing e->info, it is necessary to free the old einfo. Fixes: f25da51 ("ieee802154: hwsim: add replacement for fakelb") Reviewed-by: Miquel Raynal <[email protected]> Reviewed-by: Alexander Aring <[email protected]> Signed-off-by: Chen Aotian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stefan Schmidt <[email protected]>
1 parent 2093735 commit a616752

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/ieee802154/mac802154_hwsim.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static int hwsim_del_edge_nl(struct sk_buff *msg, struct genl_info *info)
685685
static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info)
686686
{
687687
struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX + 1];
688-
struct hwsim_edge_info *einfo;
688+
struct hwsim_edge_info *einfo, *einfo_old;
689689
struct hwsim_phy *phy_v0;
690690
struct hwsim_edge *e;
691691
u32 v0, v1;
@@ -723,8 +723,10 @@ static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info)
723723
list_for_each_entry_rcu(e, &phy_v0->edges, list) {
724724
if (e->endpoint->idx == v1) {
725725
einfo->lqi = lqi;
726-
rcu_assign_pointer(e->info, einfo);
726+
einfo_old = rcu_replace_pointer(e->info, einfo,
727+
lockdep_is_held(&hwsim_phys_lock));
727728
rcu_read_unlock();
729+
kfree_rcu(einfo_old, rcu);
728730
mutex_unlock(&hwsim_phys_lock);
729731
return 0;
730732
}

0 commit comments

Comments
 (0)