From patchwork Wed Oct 19 13:44:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13011815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5F4DC43217 for ; Wed, 19 Oct 2022 14:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231833AbiJSOFU (ORCPT ); Wed, 19 Oct 2022 10:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233929AbiJSOEI (ORCPT ); Wed, 19 Oct 2022 10:04:08 -0400 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [IPv6:2001:4b98:dc4:8::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8811ABEF2; Wed, 19 Oct 2022 06:45:25 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 3739124000A; Wed, 19 Oct 2022 13:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1666187067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fcNlh4YYDUmBXasaCeDeHRaIml7estVWt8prgBYpz1U=; b=flBd2vvfOXAXttdRKNOpi+RyE+ojteBr1uD3mrKvP8O3g2y2FosujPSx/MdS9SLIkx94vd aJ9qp33NojqP8IcZET/QsWw2ilL8dRXiIAabas7bQYXkI9ApwfoyfULdJWJ/0YYOyb0X9/ X8y0j4ZvuyMJpUpkTHFax5rgoYH38Jv08A91FU1CXxOJVleBmq6GKOdWXmAQmrKmMNVBsP WgY1I+YzO3huI9D2T2iIta6d0CDFfJRfZtEk2EMr+Qh3ecU80U9nYpJN22ED/mIejeaJi4 2CL/njFf/d2lX2UY01IlxF8mEIC/yxg7ptJrf0N+m420sIvywZcICbcNVd2sWg== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-next v6 1/3] ieee802154: hwsim: Introduce a helper to update all the PIB attributes Date: Wed, 19 Oct 2022 15:44:21 +0200 Message-Id: <20221019134423.877169-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019134423.877169-1-miquel.raynal@bootlin.com> References: <20221019134423.877169-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org 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 --- drivers/net/ieee802154/mac802154_hwsim.c | 66 +++++++++++++----------- 1 file changed, 35 insertions(+), 31 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,46 +90,20 @@ 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_old = rtnl_dereference(phy->pib); + 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; - - 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) -{ - struct hwsim_phy *phy = hw->priv; - struct hwsim_pib *pib, *pib_old; - - pib = kzalloc(sizeof(*pib), GFP_KERNEL); - if (!pib) - return -ENOMEM; - - pib_old = rtnl_dereference(phy->pib); - - pib->page = pib_old->page; - pib->channel = pib_old->channel; - pib->filt.short_addr = filt->short_addr; pib->filt.pan_id = filt->pan_id; pib->filt.ieee_addr = filt->ieee_addr; @@ -140,6 +114,36 @@ static int hwsim_hw_addr_filt(struct ieee802154_hw *hw, return 0; } +static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel) +{ + struct hwsim_phy *phy = hw->priv; + struct hwsim_pib *pib; + int ret; + + rcu_read_lock(); + pib = rcu_dereference(phy->pib); + ret = hwsim_update_pib(hw, page, channel, &pib->filt); + rcu_read_unlock(); + + return ret; +} + +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; + + rcu_read_lock(); + pib = rcu_dereference(phy->pib); + ret = hwsim_update_pib(hw, pib->page, pib->channel, filt); + rcu_read_unlock(); + + return ret; +} + static void hwsim_hw_receive(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi) {