summaryrefslogtreecommitdiff
path: root/drivers/net/ieee802154
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2022-10-19 16:44:21 +0300
committerStefan Schmidt <stefan@datenfreihafen.org>2022-10-24 10:33:35 +0300
commit9a60850e8cd9160beba79aa6d529332eb18c9bc7 (patch)
tree1b8621dc7d181380f1d31f98906d787c830cb844 /drivers/net/ieee802154
parentf8be91fbfc7dd2d69762d510cc29c3b52d3ef4db (diff)
downloadlinux-9a60850e8cd9160beba79aa6d529332eb18c9bc7.tar.xz
ieee802154: hwsim: Introduce a helper to update all the PIB attributes
Perform the update of the PIB structure only in a single place. This way we can have much simpler functions when updating the page, channel or address filters. This helper will become even more useful when we will update the ->set_promiscuous() callback to actually save the filtering level in the PIB structure. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Alexander Aring <aahringo@redhat.com> Link: https://lore.kernel.org/r/20221019134423.877169-2-miquel.raynal@bootlin.com Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
Diffstat (limited to 'drivers/net/ieee802154')
-rw-r--r--drivers/net/ieee802154/mac802154_hwsim.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
index 1db7da3ccc1a..44dbd5f27dc5 100644
--- a/drivers/net/ieee802154/mac802154_hwsim.c
+++ b/drivers/net/ieee802154/mac802154_hwsim.c
@@ -90,54 +90,58 @@ static int hwsim_hw_ed(struct ieee802154_hw *hw, u8 *level)
return 0;
}
-static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
+static int hwsim_update_pib(struct ieee802154_hw *hw, u8 page, u8 channel,
+ struct ieee802154_hw_addr_filt *filt)
{
struct hwsim_phy *phy = hw->priv;
struct hwsim_pib *pib, *pib_old;
- pib = kzalloc(sizeof(*pib), GFP_KERNEL);
+ pib = kzalloc(sizeof(*pib), GFP_ATOMIC);
if (!pib)
return -ENOMEM;
- pib->page = page;
- pib->channel = channel;
-
pib_old = rtnl_dereference(phy->pib);
- pib->filt.short_addr = pib_old->filt.short_addr;
- pib->filt.pan_id = pib_old->filt.pan_id;
- pib->filt.ieee_addr = pib_old->filt.ieee_addr;
- pib->filt.pan_coord = pib_old->filt.pan_coord;
+ pib->page = page;
+ pib->channel = channel;
+ pib->filt.short_addr = filt->short_addr;
+ pib->filt.pan_id = filt->pan_id;
+ pib->filt.ieee_addr = filt->ieee_addr;
+ pib->filt.pan_coord = filt->pan_coord;
rcu_assign_pointer(phy->pib, pib);
kfree_rcu(pib_old, rcu);
return 0;
}
-static int hwsim_hw_addr_filt(struct ieee802154_hw *hw,
- struct ieee802154_hw_addr_filt *filt,
- unsigned long changed)
+static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
{
struct hwsim_phy *phy = hw->priv;
- struct hwsim_pib *pib, *pib_old;
+ struct hwsim_pib *pib;
+ int ret;
- pib = kzalloc(sizeof(*pib), GFP_KERNEL);
- if (!pib)
- return -ENOMEM;
+ rcu_read_lock();
+ pib = rcu_dereference(phy->pib);
+ ret = hwsim_update_pib(hw, page, channel, &pib->filt);
+ rcu_read_unlock();
- pib_old = rtnl_dereference(phy->pib);
+ return ret;
+}
- pib->page = pib_old->page;
- pib->channel = pib_old->channel;
+static int hwsim_hw_addr_filt(struct ieee802154_hw *hw,
+ struct ieee802154_hw_addr_filt *filt,
+ unsigned long changed)
+{
+ struct hwsim_phy *phy = hw->priv;
+ struct hwsim_pib *pib;
+ int ret;
- pib->filt.short_addr = filt->short_addr;
- pib->filt.pan_id = filt->pan_id;
- pib->filt.ieee_addr = filt->ieee_addr;
- pib->filt.pan_coord = filt->pan_coord;
+ rcu_read_lock();
+ pib = rcu_dereference(phy->pib);
+ ret = hwsim_update_pib(hw, pib->page, pib->channel, filt);
+ rcu_read_unlock();
- rcu_assign_pointer(phy->pib, pib);
- kfree_rcu(pib_old, rcu);
- return 0;
+ return ret;
}
static void hwsim_hw_receive(struct ieee802154_hw *hw, struct sk_buff *skb,