Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wifi: cfg80211: define and use wiphy guard

Define a guard for the wiphy mutex, and use it in
most code in cfg80211, though not all due to some
interaction with RTNL and/or indentation.

Suggested-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Link: https://patch.msgid.link/20241122094225.88765cbaab65.I610c9b14f36902e75e1d13f0db29f8bef2298804@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

+277 -447
+4
include/net/cfg80211.h
··· 6031 6031 mutex_unlock(&wiphy->mtx); 6032 6032 } 6033 6033 6034 + DEFINE_GUARD(wiphy, struct wiphy *, 6035 + mutex_lock(&_T->mtx), 6036 + mutex_unlock(&_T->mtx)) 6037 + 6034 6038 struct wiphy_work; 6035 6039 typedef void (*wiphy_work_func_t)(struct wiphy *, struct wiphy_work *); 6036 6040
+2 -2
net/wireless/chan.c
··· 1039 1039 if (!reg_dfs_domain_same(wiphy, &rdev->wiphy)) 1040 1040 continue; 1041 1041 1042 - wiphy_lock(&rdev->wiphy); 1042 + guard(wiphy)(&rdev->wiphy); 1043 + 1043 1044 found = cfg80211_is_wiphy_oper_chan(&rdev->wiphy, chan) || 1044 1045 cfg80211_offchan_chain_is_active(rdev, chan); 1045 - wiphy_unlock(&rdev->wiphy); 1046 1046 1047 1047 if (found) 1048 1048 return true;
+19 -23
net/wireless/core.c
··· 191 191 return err; 192 192 } 193 193 194 - wiphy_lock(&rdev->wiphy); 194 + guard(wiphy)(&rdev->wiphy); 195 + 195 196 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 196 197 if (!wdev->netdev) 197 198 continue; ··· 213 212 continue; 214 213 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); 215 214 } 216 - wiphy_unlock(&rdev->wiphy); 217 215 218 216 return 0; 219 217 } ··· 221 221 { 222 222 struct cfg80211_registered_device *rdev = data; 223 223 224 - wiphy_lock(&rdev->wiphy); 224 + guard(wiphy)(&rdev->wiphy); 225 + 225 226 rdev_rfkill_poll(rdev); 226 - wiphy_unlock(&rdev->wiphy); 227 227 } 228 228 229 229 void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev, ··· 283 283 284 284 /* otherwise, check iftype */ 285 285 286 - wiphy_lock(wiphy); 286 + guard(wiphy)(wiphy); 287 287 288 288 switch (wdev->iftype) { 289 289 case NL80211_IFTYPE_P2P_DEVICE: ··· 295 295 default: 296 296 break; 297 297 } 298 - 299 - wiphy_unlock(wiphy); 300 298 } 301 299 } 302 300 EXPORT_SYMBOL_GPL(cfg80211_shutdown_all_interfaces); ··· 329 331 rdev = container_of(work, struct cfg80211_registered_device, 330 332 event_work); 331 333 332 - wiphy_lock(&rdev->wiphy); 334 + guard(wiphy)(&rdev->wiphy); 335 + 333 336 cfg80211_process_rdev_events(rdev); 334 - wiphy_unlock(&rdev->wiphy); 335 337 } 336 338 337 339 void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev) ··· 345 347 if (wdev->netdev) 346 348 dev_close(wdev->netdev); 347 349 348 - wiphy_lock(&rdev->wiphy); 350 + guard(wiphy)(&rdev->wiphy); 351 + 349 352 cfg80211_leave(rdev, wdev); 350 353 cfg80211_remove_virtual_intf(rdev, wdev); 351 - wiphy_unlock(&rdev->wiphy); 352 354 } 353 355 } 354 356 } ··· 421 423 422 424 trace_wiphy_work_worker_start(&rdev->wiphy); 423 425 424 - wiphy_lock(&rdev->wiphy); 426 + guard(wiphy)(&rdev->wiphy); 425 427 if (rdev->suspended) 426 - goto out; 428 + return; 427 429 428 430 spin_lock_irq(&rdev->wiphy_work_lock); 429 431 wk = list_first_entry_or_null(&rdev->wiphy_work_list, ··· 439 441 } else { 440 442 spin_unlock_irq(&rdev->wiphy_work_lock); 441 443 } 442 - out: 443 - wiphy_unlock(&rdev->wiphy); 444 444 } 445 445 446 446 /* exported functions */ ··· 1522 1526 break; 1523 1527 case NETDEV_REGISTER: 1524 1528 if (!wdev->registered) { 1525 - wiphy_lock(&rdev->wiphy); 1529 + guard(wiphy)(&rdev->wiphy); 1530 + 1526 1531 cfg80211_register_wdev(rdev, wdev); 1527 - wiphy_unlock(&rdev->wiphy); 1528 1532 } 1529 1533 break; 1530 1534 case NETDEV_UNREGISTER: ··· 1533 1537 * so check wdev->registered. 1534 1538 */ 1535 1539 if (wdev->registered && !wdev->registering) { 1536 - wiphy_lock(&rdev->wiphy); 1540 + guard(wiphy)(&rdev->wiphy); 1541 + 1537 1542 _cfg80211_unregister_wdev(wdev, false); 1538 - wiphy_unlock(&rdev->wiphy); 1539 1543 } 1540 1544 break; 1541 1545 case NETDEV_GOING_DOWN: 1542 - wiphy_lock(&rdev->wiphy); 1543 - cfg80211_leave(rdev, wdev); 1544 - cfg80211_remove_links(wdev); 1545 - wiphy_unlock(&rdev->wiphy); 1546 + scoped_guard(wiphy, &rdev->wiphy) { 1547 + cfg80211_leave(rdev, wdev); 1548 + cfg80211_remove_links(wdev); 1549 + } 1546 1550 /* since we just did cfg80211_leave() nothing to do there */ 1547 1551 cancel_work_sync(&wdev->disconnect_wk); 1548 1552 cancel_work_sync(&wdev->pmsr_free_wk);
+4 -4
net/wireless/mlme.c
··· 627 627 rdev = container_of(wk, struct cfg80211_registered_device, 628 628 mgmt_registrations_update_wk); 629 629 630 - wiphy_lock(&rdev->wiphy); 630 + guard(wiphy)(&rdev->wiphy); 631 + 631 632 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) 632 633 cfg80211_mgmt_registrations_update(wdev); 633 - wiphy_unlock(&rdev->wiphy); 634 634 } 635 635 636 636 int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid, ··· 1193 1193 const struct cfg80211_chan_def *chandef, 1194 1194 enum nl80211_radar_event event) 1195 1195 { 1196 - wiphy_lock(&rdev->wiphy); 1196 + guard(wiphy)(&rdev->wiphy); 1197 + 1197 1198 __cfg80211_background_cac_event(rdev, rdev->background_radar_wdev, 1198 1199 chandef, event); 1199 - wiphy_unlock(&rdev->wiphy); 1200 1200 } 1201 1201 1202 1202 void cfg80211_background_cac_done_wk(struct work_struct *work)
+71 -119
net/wireless/nl80211.c
··· 3626 3626 } else 3627 3627 wdev = netdev->ieee80211_ptr; 3628 3628 3629 - wiphy_lock(&rdev->wiphy); 3629 + guard(wiphy)(&rdev->wiphy); 3630 3630 3631 3631 /* 3632 3632 * end workaround code, by now the rdev is available ··· 3639 3639 rtnl_unlock(); 3640 3640 3641 3641 if (result) 3642 - goto out; 3642 + return result; 3643 3643 3644 3644 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 3645 3645 struct ieee80211_txq_params txq_params; 3646 3646 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 3647 3647 3648 - if (!rdev->ops->set_txq_params) { 3649 - result = -EOPNOTSUPP; 3650 - goto out; 3651 - } 3648 + if (!rdev->ops->set_txq_params) 3649 + return -EOPNOTSUPP; 3652 3650 3653 - if (!netdev) { 3654 - result = -EINVAL; 3655 - goto out; 3656 - } 3651 + if (!netdev) 3652 + return -EINVAL; 3657 3653 3658 3654 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3659 - netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 3660 - result = -EINVAL; 3661 - goto out; 3662 - } 3655 + netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 3656 + return -EINVAL; 3663 3657 3664 - if (!netif_running(netdev)) { 3665 - result = -ENETDOWN; 3666 - goto out; 3667 - } 3658 + if (!netif_running(netdev)) 3659 + return -ENETDOWN; 3668 3660 3669 3661 nla_for_each_nested(nl_txq_params, 3670 3662 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], ··· 3667 3675 txq_params_policy, 3668 3676 info->extack); 3669 3677 if (result) 3670 - goto out; 3678 + return result; 3679 + 3671 3680 result = parse_txq_params(tb, &txq_params); 3672 3681 if (result) 3673 - goto out; 3682 + return result; 3674 3683 3675 3684 txq_params.link_id = 3676 3685 nl80211_link_id_or_invalid(info->attrs); ··· 3687 3694 result = rdev_set_txq_params(rdev, netdev, 3688 3695 &txq_params); 3689 3696 if (result) 3690 - goto out; 3697 + return result; 3691 3698 } 3692 3699 } 3693 3700 ··· 3704 3711 } 3705 3712 3706 3713 if (result) 3707 - goto out; 3714 + return result; 3708 3715 } 3709 3716 3710 3717 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { ··· 3715 3722 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 3716 3723 txp_wdev = NULL; 3717 3724 3718 - if (!rdev->ops->set_tx_power) { 3719 - result = -EOPNOTSUPP; 3720 - goto out; 3721 - } 3725 + if (!rdev->ops->set_tx_power) 3726 + return -EOPNOTSUPP; 3722 3727 3723 3728 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 3724 3729 type = nla_get_u32(info->attrs[idx]); 3725 3730 3726 3731 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 3727 - (type != NL80211_TX_POWER_AUTOMATIC)) { 3728 - result = -EINVAL; 3729 - goto out; 3730 - } 3732 + (type != NL80211_TX_POWER_AUTOMATIC)) 3733 + return -EINVAL; 3731 3734 3732 3735 if (type != NL80211_TX_POWER_AUTOMATIC) { 3733 3736 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; ··· 3732 3743 3733 3744 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 3734 3745 if (result) 3735 - goto out; 3746 + return result; 3736 3747 } 3737 3748 3738 3749 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && ··· 3741 3752 3742 3753 if ((!rdev->wiphy.available_antennas_tx && 3743 3754 !rdev->wiphy.available_antennas_rx) || 3744 - !rdev->ops->set_antenna) { 3745 - result = -EOPNOTSUPP; 3746 - goto out; 3747 - } 3755 + !rdev->ops->set_antenna) 3756 + return -EOPNOTSUPP; 3748 3757 3749 3758 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 3750 3759 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); ··· 3750 3763 /* reject antenna configurations which don't match the 3751 3764 * available antenna masks, except for the "all" mask */ 3752 3765 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 3753 - (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { 3754 - result = -EINVAL; 3755 - goto out; 3756 - } 3766 + (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) 3767 + return -EINVAL; 3757 3768 3758 3769 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 3759 3770 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 3760 3771 3761 3772 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 3762 3773 if (result) 3763 - goto out; 3774 + return result; 3764 3775 } 3765 3776 3766 3777 changed = 0; ··· 3780 3795 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 3781 3796 frag_threshold = nla_get_u32( 3782 3797 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 3783 - if (frag_threshold < 256) { 3784 - result = -EINVAL; 3785 - goto out; 3786 - } 3798 + if (frag_threshold < 256) 3799 + return -EINVAL; 3787 3800 3788 3801 if (frag_threshold != (u32) -1) { 3789 3802 /* ··· 3802 3819 } 3803 3820 3804 3821 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 3805 - if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3806 - result = -EINVAL; 3807 - goto out; 3808 - } 3822 + if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) 3823 + return -EINVAL; 3809 3824 3810 3825 coverage_class = nla_get_u8( 3811 3826 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); ··· 3811 3830 } 3812 3831 3813 3832 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3814 - if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { 3815 - result = -EOPNOTSUPP; 3816 - goto out; 3817 - } 3833 + if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) 3834 + return -EOPNOTSUPP; 3818 3835 3819 3836 changed |= WIPHY_PARAM_DYN_ACK; 3820 3837 } 3821 3838 3822 3839 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 3823 3840 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3824 - NL80211_EXT_FEATURE_TXQS)) { 3825 - result = -EOPNOTSUPP; 3826 - goto out; 3827 - } 3841 + NL80211_EXT_FEATURE_TXQS)) 3842 + return -EOPNOTSUPP; 3843 + 3828 3844 txq_limit = nla_get_u32( 3829 3845 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 3830 3846 changed |= WIPHY_PARAM_TXQ_LIMIT; ··· 3829 3851 3830 3852 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 3831 3853 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3832 - NL80211_EXT_FEATURE_TXQS)) { 3833 - result = -EOPNOTSUPP; 3834 - goto out; 3835 - } 3854 + NL80211_EXT_FEATURE_TXQS)) 3855 + return -EOPNOTSUPP; 3856 + 3836 3857 txq_memory_limit = nla_get_u32( 3837 3858 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 3838 3859 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; ··· 3839 3862 3840 3863 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 3841 3864 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3842 - NL80211_EXT_FEATURE_TXQS)) { 3843 - result = -EOPNOTSUPP; 3844 - goto out; 3845 - } 3865 + NL80211_EXT_FEATURE_TXQS)) 3866 + return -EOPNOTSUPP; 3867 + 3846 3868 txq_quantum = nla_get_u32( 3847 3869 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 3848 3870 changed |= WIPHY_PARAM_TXQ_QUANTUM; ··· 3853 3877 u8 old_coverage_class; 3854 3878 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 3855 3879 3856 - if (!rdev->ops->set_wiphy_params) { 3857 - result = -EOPNOTSUPP; 3858 - goto out; 3859 - } 3880 + if (!rdev->ops->set_wiphy_params) 3881 + return -EOPNOTSUPP; 3860 3882 3861 3883 old_retry_short = rdev->wiphy.retry_short; 3862 3884 old_retry_long = rdev->wiphy.retry_long; ··· 3892 3918 rdev->wiphy.txq_limit = old_txq_limit; 3893 3919 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3894 3920 rdev->wiphy.txq_quantum = old_txq_quantum; 3895 - goto out; 3921 + return result; 3896 3922 } 3897 3923 } 3898 3924 3899 - result = 0; 3900 - 3901 - out: 3902 - wiphy_unlock(&rdev->wiphy); 3903 - return result; 3925 + return 0; 3904 3926 } 3905 3927 3906 3928 int nl80211_send_chandef(struct sk_buff *msg, const struct cfg80211_chan_def *chandef) ··· 4114 4144 4115 4145 if_idx = 0; 4116 4146 4117 - wiphy_lock(&rdev->wiphy); 4147 + guard(wiphy)(&rdev->wiphy); 4148 + 4118 4149 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 4119 4150 if (if_idx < if_start) { 4120 4151 if_idx++; 4121 4152 continue; 4122 4153 } 4154 + 4123 4155 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 4124 4156 cb->nlh->nlmsg_seq, NLM_F_MULTI, 4125 4157 rdev, wdev, 4126 - NL80211_CMD_NEW_INTERFACE) < 0) { 4127 - wiphy_unlock(&rdev->wiphy); 4158 + NL80211_CMD_NEW_INTERFACE) < 0) 4128 4159 goto out; 4129 - } 4160 + 4130 4161 if_idx++; 4131 4162 } 4132 - wiphy_unlock(&rdev->wiphy); 4133 4163 4134 4164 if_start = 0; 4135 4165 wp_idx++; ··· 4487 4517 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4488 4518 { 4489 4519 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4490 - int ret; 4491 4520 4492 4521 /* to avoid failing a new interface creation due to pending removal */ 4493 4522 cfg80211_destroy_ifaces(rdev); 4494 4523 4495 - wiphy_lock(&rdev->wiphy); 4496 - ret = _nl80211_new_interface(skb, info); 4497 - wiphy_unlock(&rdev->wiphy); 4524 + guard(wiphy)(&rdev->wiphy); 4498 4525 4499 - return ret; 4526 + return _nl80211_new_interface(skb, info); 4500 4527 } 4501 4528 4502 4529 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) ··· 10065 10098 struct cfg80211_chan_def chandef; 10066 10099 enum nl80211_dfs_regions dfs_region; 10067 10100 unsigned int cac_time_ms; 10068 - int err = -EINVAL; 10101 + int err; 10069 10102 10070 10103 flush_delayed_work(&rdev->dfs_update_channels_wk); 10071 10104 ··· 10080 10113 return -EINVAL; 10081 10114 } 10082 10115 10083 - wiphy_lock(wiphy); 10116 + guard(wiphy)(wiphy); 10084 10117 10085 10118 dfs_region = reg_get_dfs_region(wiphy); 10086 10119 if (dfs_region == NL80211_DFS_UNSET) 10087 - goto unlock; 10120 + return -EINVAL; 10088 10121 10089 10122 err = nl80211_parse_chandef(rdev, info, &chandef); 10090 10123 if (err) 10091 - goto unlock; 10124 + return err; 10092 10125 10093 10126 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 10094 10127 if (err < 0) 10095 - goto unlock; 10128 + return err; 10096 10129 10097 - if (err == 0) { 10098 - err = -EINVAL; 10099 - goto unlock; 10100 - } 10130 + if (err == 0) 10131 + return -EINVAL; 10101 10132 10102 - if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) { 10103 - err = -EINVAL; 10104 - goto unlock; 10105 - } 10133 + if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) 10134 + return -EINVAL; 10106 10135 10107 - if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) { 10108 - err = cfg80211_start_background_radar_detection(rdev, wdev, 10109 - &chandef); 10110 - goto unlock; 10111 - } 10136 + if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) 10137 + return cfg80211_start_background_radar_detection(rdev, wdev, 10138 + &chandef); 10112 10139 10113 10140 if (cfg80211_beaconing_iface_active(wdev)) { 10114 10141 /* During MLO other link(s) can beacon, only the current link ··· 10112 10151 !wdev->links[link_id].ap.beacon_interval) { 10113 10152 /* nothing */ 10114 10153 } else { 10115 - err = -EBUSY; 10116 - goto unlock; 10154 + return -EBUSY; 10117 10155 } 10118 10156 } 10119 10157 10120 - if (wdev->links[link_id].cac_started) { 10121 - err = -EBUSY; 10122 - goto unlock; 10123 - } 10158 + if (wdev->links[link_id].cac_started) 10159 + return -EBUSY; 10124 10160 10125 10161 /* CAC start is offloaded to HW and can't be started manually */ 10126 - if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) { 10127 - err = -EOPNOTSUPP; 10128 - goto unlock; 10129 - } 10162 + if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) 10163 + return -EOPNOTSUPP; 10130 10164 10131 - if (!rdev->ops->start_radar_detection) { 10132 - err = -EOPNOTSUPP; 10133 - goto unlock; 10134 - } 10165 + if (!rdev->ops->start_radar_detection) 10166 + return -EOPNOTSUPP; 10135 10167 10136 10168 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 10137 10169 if (WARN_ON(!cac_time_ms)) ··· 10151 10197 wdev->links[link_id].cac_start_time = jiffies; 10152 10198 wdev->links[link_id].cac_time_ms = cac_time_ms; 10153 10199 } 10154 - unlock: 10155 - wiphy_unlock(wiphy); 10156 10200 10157 - return err; 10201 + return 0; 10158 10202 } 10159 10203 10160 10204 static int nl80211_notify_radar_detection(struct sk_buff *skb,
+2 -2
net/wireless/pmsr.c
··· 630 630 struct wireless_dev *wdev = container_of(work, struct wireless_dev, 631 631 pmsr_free_wk); 632 632 633 - wiphy_lock(wdev->wiphy); 633 + guard(wiphy)(wdev->wiphy); 634 + 634 635 cfg80211_pmsr_process_abort(wdev); 635 - wiphy_unlock(wdev->wiphy); 636 636 } 637 637 638 638 void cfg80211_pmsr_wdev_down(struct wireless_dev *wdev)
+24 -29
net/wireless/reg.c
··· 2465 2465 struct wireless_dev *wdev; 2466 2466 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 2467 2467 2468 - wiphy_lock(wiphy); 2468 + guard(wiphy)(wiphy); 2469 + 2469 2470 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) 2470 2471 if (!reg_wdev_chan_valid(wiphy, wdev)) 2471 2472 cfg80211_leave(rdev, wdev); 2472 - wiphy_unlock(wiphy); 2473 2473 } 2474 2474 2475 2475 static void reg_check_chans_work(struct work_struct *work) ··· 2649 2649 return; 2650 2650 2651 2651 rtnl_lock(); 2652 - wiphy_lock(wiphy); 2653 - 2654 - tmp = get_wiphy_regdom(wiphy); 2655 - rcu_assign_pointer(wiphy->regd, new_regd); 2656 - rcu_free_regdom(tmp); 2657 - 2658 - wiphy_unlock(wiphy); 2652 + scoped_guard(wiphy, wiphy) { 2653 + tmp = get_wiphy_regdom(wiphy); 2654 + rcu_assign_pointer(wiphy->regd, new_regd); 2655 + rcu_free_regdom(tmp); 2656 + } 2659 2657 rtnl_unlock(); 2660 2658 } 2661 2659 EXPORT_SYMBOL(wiphy_apply_custom_regulatory); ··· 2823 2825 2824 2826 tmp = get_wiphy_regdom(wiphy); 2825 2827 ASSERT_RTNL(); 2826 - wiphy_lock(wiphy); 2827 - rcu_assign_pointer(wiphy->regd, regd); 2828 - wiphy_unlock(wiphy); 2828 + scoped_guard(wiphy, wiphy) { 2829 + rcu_assign_pointer(wiphy->regd, regd); 2830 + } 2829 2831 rcu_free_regdom(tmp); 2830 2832 } 2831 2833 ··· 3203 3205 ASSERT_RTNL(); 3204 3206 3205 3207 for_each_rdev(rdev) { 3206 - wiphy_lock(&rdev->wiphy); 3208 + guard(wiphy)(&rdev->wiphy); 3209 + 3207 3210 reg_process_self_managed_hint(&rdev->wiphy); 3208 - wiphy_unlock(&rdev->wiphy); 3209 3211 } 3210 3212 3211 3213 reg_check_channels(); ··· 3598 3600 struct wireless_dev *wdev; 3599 3601 3600 3602 for_each_rdev(rdev) { 3601 - wiphy_lock(&rdev->wiphy); 3603 + guard(wiphy)(&rdev->wiphy); 3604 + 3602 3605 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 3603 - if (!(wdev->wiphy->regulatory_flags & flag)) { 3604 - wiphy_unlock(&rdev->wiphy); 3606 + if (!(wdev->wiphy->regulatory_flags & flag)) 3605 3607 return false; 3606 - } 3607 3608 } 3608 - wiphy_unlock(&rdev->wiphy); 3609 3609 } 3610 3610 3611 3611 return true; ··· 3879 3883 3880 3884 if (!driver_request->intersect) { 3881 3885 ASSERT_RTNL(); 3882 - wiphy_lock(request_wiphy); 3883 - if (request_wiphy->regd) 3884 - tmp = get_wiphy_regdom(request_wiphy); 3886 + scoped_guard(wiphy, request_wiphy) { 3887 + if (request_wiphy->regd) 3888 + tmp = get_wiphy_regdom(request_wiphy); 3885 3889 3886 - regd = reg_copy_regd(rd); 3887 - if (IS_ERR(regd)) { 3888 - wiphy_unlock(request_wiphy); 3889 - return PTR_ERR(regd); 3890 + regd = reg_copy_regd(rd); 3891 + if (IS_ERR(regd)) 3892 + return PTR_ERR(regd); 3893 + 3894 + rcu_assign_pointer(request_wiphy->regd, regd); 3895 + rcu_free_regdom(tmp); 3890 3896 } 3891 3897 3892 - rcu_assign_pointer(request_wiphy->regd, regd); 3893 - rcu_free_regdom(tmp); 3894 - wiphy_unlock(request_wiphy); 3895 3898 reset_regdomains(false, rd); 3896 3899 return 0; 3897 3900 }
+19 -21
net/wireless/scan.c
··· 1238 1238 rdev = container_of(work, struct cfg80211_registered_device, 1239 1239 sched_scan_res_wk); 1240 1240 1241 - wiphy_lock(&rdev->wiphy); 1241 + guard(wiphy)(&rdev->wiphy); 1242 + 1242 1243 list_for_each_entry_safe(req, tmp, &rdev->sched_scan_req_list, list) { 1243 1244 if (req->report_results) { 1244 1245 req->report_results = false; ··· 1254 1253 NL80211_CMD_SCHED_SCAN_RESULTS); 1255 1254 } 1256 1255 } 1257 - wiphy_unlock(&rdev->wiphy); 1258 1256 } 1259 1257 1260 1258 void cfg80211_sched_scan_results(struct wiphy *wiphy, u64 reqid) ··· 1288 1288 1289 1289 void cfg80211_sched_scan_stopped(struct wiphy *wiphy, u64 reqid) 1290 1290 { 1291 - wiphy_lock(wiphy); 1291 + guard(wiphy)(wiphy); 1292 + 1292 1293 cfg80211_sched_scan_stopped_locked(wiphy, reqid); 1293 - wiphy_unlock(wiphy); 1294 1294 } 1295 1295 EXPORT_SYMBOL(cfg80211_sched_scan_stopped); 1296 1296 ··· 3565 3565 /* translate "Scan for SSID" request */ 3566 3566 if (wreq) { 3567 3567 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 3568 - if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) { 3569 - err = -EINVAL; 3570 - goto out; 3571 - } 3568 + if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) 3569 + return -EINVAL; 3572 3570 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len); 3573 3571 creq->ssids[0].ssid_len = wreq->essid_len; 3574 3572 } ··· 3582 3584 3583 3585 eth_broadcast_addr(creq->bssid); 3584 3586 3585 - wiphy_lock(&rdev->wiphy); 3586 - 3587 - rdev->scan_req = creq; 3588 - err = rdev_scan(rdev, creq); 3589 - if (err) { 3590 - rdev->scan_req = NULL; 3591 - /* creq will be freed below */ 3592 - } else { 3593 - nl80211_send_scan_start(rdev, dev->ieee80211_ptr); 3594 - /* creq now owned by driver */ 3595 - creq = NULL; 3596 - dev_hold(dev); 3587 + scoped_guard(wiphy, &rdev->wiphy) { 3588 + rdev->scan_req = creq; 3589 + err = rdev_scan(rdev, creq); 3590 + if (err) { 3591 + rdev->scan_req = NULL; 3592 + /* creq will be freed below */ 3593 + } else { 3594 + nl80211_send_scan_start(rdev, dev->ieee80211_ptr); 3595 + /* creq now owned by driver */ 3596 + creq = NULL; 3597 + dev_hold(dev); 3598 + } 3597 3599 } 3598 - wiphy_unlock(&rdev->wiphy); 3600 + 3599 3601 out: 3600 3602 kfree(creq); 3601 3603 return err;
+4 -8
net/wireless/sme.c
··· 251 251 u8 bssid_buf[ETH_ALEN], *bssid = NULL; 252 252 enum nl80211_timeout_reason treason; 253 253 254 - wiphy_lock(&rdev->wiphy); 254 + guard(wiphy)(&rdev->wiphy); 255 255 256 256 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 257 257 if (!wdev->netdev) ··· 279 279 __cfg80211_connect_result(wdev->netdev, &cr, false); 280 280 } 281 281 } 282 - 283 - wiphy_unlock(&rdev->wiphy); 284 282 } 285 283 286 284 static void cfg80211_step_auth_next(struct cfg80211_conn *conn, ··· 690 692 * as chan dfs state, etc. 691 693 */ 692 694 for_each_rdev(rdev) { 693 - wiphy_lock(&rdev->wiphy); 695 + guard(wiphy)(&rdev->wiphy); 696 + 694 697 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 695 698 if (wdev->conn || wdev->connected || 696 699 cfg80211_beaconing_iface_active(wdev)) 697 700 is_all_idle = false; 698 701 } 699 - wiphy_unlock(&rdev->wiphy); 700 702 } 701 703 702 704 return is_all_idle; ··· 1580 1582 container_of(work, struct wireless_dev, disconnect_wk); 1581 1583 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1582 1584 1583 - wiphy_lock(wdev->wiphy); 1585 + guard(wiphy)(wdev->wiphy); 1584 1586 1585 1587 if (wdev->conn_owner_nlportid) { 1586 1588 switch (wdev->iftype) { ··· 1616 1618 break; 1617 1619 } 1618 1620 } 1619 - 1620 - wiphy_unlock(wdev->wiphy); 1621 1621 }
+2 -5
net/wireless/util.c
··· 2572 2572 { 2573 2573 struct cfg80211_registered_device *rdev; 2574 2574 struct wireless_dev *wdev; 2575 - int ret; 2576 2575 2577 2576 wdev = dev->ieee80211_ptr; 2578 2577 if (!wdev) ··· 2583 2584 2584 2585 memset(sinfo, 0, sizeof(*sinfo)); 2585 2586 2586 - wiphy_lock(&rdev->wiphy); 2587 - ret = rdev_get_station(rdev, dev, mac_addr, sinfo); 2588 - wiphy_unlock(&rdev->wiphy); 2587 + guard(wiphy)(&rdev->wiphy); 2589 2588 2590 - return ret; 2589 + return rdev_get_station(rdev, dev, mac_addr, sinfo); 2591 2590 } 2592 2591 EXPORT_SYMBOL(cfg80211_get_station); 2593 2592
+111 -206
net/wireless/wext-compat.c
··· 39 39 struct cfg80211_registered_device *rdev; 40 40 struct vif_params vifparams; 41 41 enum nl80211_iftype type; 42 - int ret; 43 42 44 43 rdev = wiphy_to_rdev(wdev->wiphy); 45 44 ··· 61 62 62 63 memset(&vifparams, 0, sizeof(vifparams)); 63 64 64 - wiphy_lock(wdev->wiphy); 65 - ret = cfg80211_change_iface(rdev, dev, type, &vifparams); 66 - wiphy_unlock(wdev->wiphy); 65 + guard(wiphy)(wdev->wiphy); 67 66 68 - return ret; 67 + return cfg80211_change_iface(rdev, dev, type, &vifparams); 69 68 } 70 69 71 70 int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info, ··· 255 258 u32 orts = wdev->wiphy->rts_threshold; 256 259 int err; 257 260 258 - wiphy_lock(&rdev->wiphy); 259 - if (rts->disabled || !rts->fixed) { 261 + guard(wiphy)(&rdev->wiphy); 262 + if (rts->disabled || !rts->fixed) 260 263 wdev->wiphy->rts_threshold = (u32) -1; 261 - } else if (rts->value < 0) { 262 - err = -EINVAL; 263 - goto out; 264 - } else { 264 + else if (rts->value < 0) 265 + return -EINVAL; 266 + else 265 267 wdev->wiphy->rts_threshold = rts->value; 266 - } 267 268 268 269 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_RTS_THRESHOLD); 269 - 270 270 if (err) 271 271 wdev->wiphy->rts_threshold = orts; 272 - 273 - out: 274 - wiphy_unlock(&rdev->wiphy); 275 272 return err; 276 273 } 277 274 ··· 293 302 u32 ofrag = wdev->wiphy->frag_threshold; 294 303 int err; 295 304 296 - wiphy_lock(&rdev->wiphy); 305 + guard(wiphy)(&rdev->wiphy); 306 + 297 307 if (frag->disabled || !frag->fixed) { 298 308 wdev->wiphy->frag_threshold = (u32) -1; 299 309 } else if (frag->value < 256) { 300 - err = -EINVAL; 301 - goto out; 310 + return -EINVAL; 302 311 } else { 303 312 /* Fragment length must be even, so strip LSB. */ 304 313 wdev->wiphy->frag_threshold = frag->value & ~0x1; ··· 307 316 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_FRAG_THRESHOLD); 308 317 if (err) 309 318 wdev->wiphy->frag_threshold = ofrag; 310 - out: 311 - wiphy_unlock(&rdev->wiphy); 312 - 313 319 return err; 314 320 } 315 321 ··· 340 352 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) 341 353 return -EINVAL; 342 354 343 - wiphy_lock(&rdev->wiphy); 355 + guard(wiphy)(&rdev->wiphy); 356 + 344 357 if (retry->flags & IW_RETRY_LONG) { 345 358 wdev->wiphy->retry_long = retry->value; 346 359 changed |= WIPHY_PARAM_RETRY_LONG; ··· 360 371 wdev->wiphy->retry_short = oshort; 361 372 wdev->wiphy->retry_long = olong; 362 373 } 363 - wiphy_unlock(&rdev->wiphy); 364 374 365 375 return err; 366 376 } ··· 566 578 struct iw_point *erq = &wrqu->encoding; 567 579 struct wireless_dev *wdev = dev->ieee80211_ptr; 568 580 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 569 - int idx, err; 570 - bool remove = false; 571 581 struct key_params params; 582 + bool remove = false; 583 + int idx; 572 584 573 585 if (wdev->iftype != NL80211_IFTYPE_STATION && 574 586 wdev->iftype != NL80211_IFTYPE_ADHOC) ··· 580 592 !rdev->ops->set_default_key) 581 593 return -EOPNOTSUPP; 582 594 583 - wiphy_lock(&rdev->wiphy); 584 - if (wdev->valid_links) { 585 - err = -EOPNOTSUPP; 586 - goto out; 587 - } 595 + guard(wiphy)(&rdev->wiphy); 596 + if (wdev->valid_links) 597 + return -EOPNOTSUPP; 588 598 589 599 idx = erq->flags & IW_ENCODE_INDEX; 590 600 if (idx == 0) { ··· 590 604 if (idx < 0) 591 605 idx = 0; 592 606 } else if (idx < 1 || idx > 4) { 593 - err = -EINVAL; 594 - goto out; 607 + return -EINVAL; 595 608 } else { 596 609 idx--; 597 610 } ··· 599 614 remove = true; 600 615 else if (erq->length == 0) { 601 616 /* No key data - just set the default TX key index */ 602 - err = 0; 617 + int err = 0; 618 + 603 619 if (wdev->connected || 604 620 (wdev->iftype == NL80211_IFTYPE_ADHOC && 605 621 wdev->u.ibss.current_bss)) ··· 608 622 true); 609 623 if (!err) 610 624 wdev->wext.default_key = idx; 611 - goto out; 625 + return err; 612 626 } 613 627 614 628 memset(&params, 0, sizeof(params)); 615 629 params.key = keybuf; 616 630 params.key_len = erq->length; 617 - if (erq->length == 5) { 631 + if (erq->length == 5) 618 632 params.cipher = WLAN_CIPHER_SUITE_WEP40; 619 - } else if (erq->length == 13) { 633 + else if (erq->length == 13) 620 634 params.cipher = WLAN_CIPHER_SUITE_WEP104; 621 - } else if (!remove) { 622 - err = -EINVAL; 623 - goto out; 624 - } 635 + else if (!remove) 636 + return -EINVAL; 625 637 626 - err = cfg80211_set_encryption(rdev, dev, false, NULL, remove, 627 - wdev->wext.default_key == -1, 628 - idx, &params); 629 - out: 630 - wiphy_unlock(&rdev->wiphy); 631 - 632 - return err; 638 + return cfg80211_set_encryption(rdev, dev, false, NULL, remove, 639 + wdev->wext.default_key == -1, 640 + idx, &params); 633 641 } 634 642 635 643 static int cfg80211_wext_siwencodeext(struct net_device *dev, ··· 639 659 bool remove = false; 640 660 struct key_params params; 641 661 u32 cipher; 642 - int ret; 643 662 644 663 if (wdev->iftype != NL80211_IFTYPE_STATION && 645 664 wdev->iftype != NL80211_IFTYPE_ADHOC) ··· 713 734 params.seq_len = 6; 714 735 } 715 736 716 - wiphy_lock(wdev->wiphy); 717 - ret = cfg80211_set_encryption( 718 - rdev, dev, 719 - !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY), 720 - addr, remove, 721 - ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, 722 - idx, &params); 723 - wiphy_unlock(wdev->wiphy); 737 + guard(wiphy)(wdev->wiphy); 724 738 725 - return ret; 739 + return cfg80211_set_encryption(rdev, dev, 740 + !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY), 741 + addr, remove, 742 + ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, 743 + idx, &params); 726 744 } 727 745 728 746 static int cfg80211_wext_giwencode(struct net_device *dev, ··· 770 794 struct cfg80211_chan_def chandef = { 771 795 .width = NL80211_CHAN_WIDTH_20_NOHT, 772 796 }; 773 - int freq, ret; 797 + int freq; 774 798 775 - wiphy_lock(&rdev->wiphy); 799 + guard(wiphy)(&rdev->wiphy); 776 800 777 801 switch (wdev->iftype) { 778 802 case NL80211_IFTYPE_STATION: 779 - ret = cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra); 780 - break; 803 + return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra); 781 804 case NL80211_IFTYPE_ADHOC: 782 - ret = cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra); 783 - break; 805 + return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra); 784 806 case NL80211_IFTYPE_MONITOR: 785 807 freq = cfg80211_wext_freq(wextfreq); 786 - if (freq < 0) { 787 - ret = freq; 788 - break; 789 - } 790 - if (freq == 0) { 791 - ret = -EINVAL; 792 - break; 793 - } 808 + if (freq < 0) 809 + return freq; 810 + if (freq == 0) 811 + return -EINVAL; 812 + 794 813 chandef.center_freq1 = freq; 795 814 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq); 796 - if (!chandef.chan) { 797 - ret = -EINVAL; 798 - break; 799 - } 800 - ret = cfg80211_set_monitor_channel(rdev, dev, &chandef); 801 - break; 815 + if (!chandef.chan) 816 + return -EINVAL; 817 + return cfg80211_set_monitor_channel(rdev, dev, &chandef); 802 818 case NL80211_IFTYPE_MESH_POINT: 803 819 freq = cfg80211_wext_freq(wextfreq); 804 - if (freq < 0) { 805 - ret = freq; 806 - break; 807 - } 808 - if (freq == 0) { 809 - ret = -EINVAL; 810 - break; 811 - } 820 + if (freq < 0) 821 + return freq; 822 + if (freq == 0) 823 + return -EINVAL; 812 824 chandef.center_freq1 = freq; 813 825 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq); 814 - if (!chandef.chan) { 815 - ret = -EINVAL; 816 - break; 817 - } 818 - ret = cfg80211_set_mesh_channel(rdev, wdev, &chandef); 819 - break; 826 + if (!chandef.chan) 827 + return -EINVAL; 828 + return cfg80211_set_mesh_channel(rdev, wdev, &chandef); 820 829 default: 821 - ret = -EOPNOTSUPP; 822 - break; 830 + return -EOPNOTSUPP; 823 831 } 824 - 825 - wiphy_unlock(&rdev->wiphy); 826 - 827 - return ret; 828 832 } 829 833 830 834 static int cfg80211_wext_giwfreq(struct net_device *dev, ··· 817 861 struct cfg80211_chan_def chandef = {}; 818 862 int ret; 819 863 820 - wiphy_lock(&rdev->wiphy); 864 + guard(wiphy)(&rdev->wiphy); 865 + 821 866 switch (wdev->iftype) { 822 867 case NL80211_IFTYPE_STATION: 823 - ret = cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); 824 - break; 868 + return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); 825 869 case NL80211_IFTYPE_ADHOC: 826 - ret = cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); 827 - break; 870 + return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); 828 871 case NL80211_IFTYPE_MONITOR: 829 - if (!rdev->ops->get_channel) { 830 - ret = -EINVAL; 831 - break; 832 - } 872 + if (!rdev->ops->get_channel) 873 + return -EINVAL; 833 874 834 875 ret = rdev_get_channel(rdev, wdev, 0, &chandef); 835 876 if (ret) 836 - break; 877 + return ret; 837 878 freq->m = chandef.chan->center_freq; 838 879 freq->e = 6; 839 - ret = 0; 840 - break; 880 + return ret; 841 881 default: 842 - ret = -EINVAL; 843 - break; 882 + return -EINVAL; 844 883 } 845 - 846 - wiphy_unlock(&rdev->wiphy); 847 - 848 - return ret; 849 884 } 850 885 851 886 static int cfg80211_wext_siwtxpower(struct net_device *dev, ··· 847 900 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 848 901 enum nl80211_tx_power_setting type; 849 902 int dbm = 0; 850 - int ret; 851 903 852 904 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 853 905 return -EINVAL; ··· 888 942 return 0; 889 943 } 890 944 891 - wiphy_lock(&rdev->wiphy); 892 - ret = rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm)); 893 - wiphy_unlock(&rdev->wiphy); 945 + guard(wiphy)(&rdev->wiphy); 894 946 895 - return ret; 947 + return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm)); 896 948 } 897 949 898 950 static int cfg80211_wext_giwtxpower(struct net_device *dev, ··· 909 965 if (!rdev->ops->get_tx_power) 910 966 return -EOPNOTSUPP; 911 967 912 - wiphy_lock(&rdev->wiphy); 913 - err = rdev_get_tx_power(rdev, wdev, &val); 914 - wiphy_unlock(&rdev->wiphy); 968 + scoped_guard(wiphy, &rdev->wiphy) { 969 + err = rdev_get_tx_power(rdev, wdev, &val); 970 + } 915 971 if (err) 916 972 return err; 917 973 ··· 1153 1209 timeout = wrq->value / 1000; 1154 1210 } 1155 1211 1156 - wiphy_lock(&rdev->wiphy); 1212 + guard(wiphy)(&rdev->wiphy); 1213 + 1157 1214 err = rdev_set_power_mgmt(rdev, dev, ps, timeout); 1158 - wiphy_unlock(&rdev->wiphy); 1159 1215 if (err) 1160 1216 return err; 1161 1217 ··· 1188 1244 struct cfg80211_bitrate_mask mask; 1189 1245 u32 fixed, maxrate; 1190 1246 struct ieee80211_supported_band *sband; 1191 - int band, ridx, ret; 1192 1247 bool match = false; 1248 + int band, ridx; 1193 1249 1194 1250 if (!rdev->ops->set_bitrate_mask) 1195 1251 return -EOPNOTSUPP; ··· 1227 1283 if (!match) 1228 1284 return -EINVAL; 1229 1285 1230 - wiphy_lock(&rdev->wiphy); 1231 - if (dev->ieee80211_ptr->valid_links) 1232 - ret = -EOPNOTSUPP; 1233 - else 1234 - ret = rdev_set_bitrate_mask(rdev, dev, 0, NULL, &mask); 1235 - wiphy_unlock(&rdev->wiphy); 1286 + guard(wiphy)(&rdev->wiphy); 1236 1287 1237 - return ret; 1288 + if (dev->ieee80211_ptr->valid_links) 1289 + return -EOPNOTSUPP; 1290 + 1291 + return rdev_set_bitrate_mask(rdev, dev, 0, NULL, &mask); 1238 1292 } 1239 1293 1240 1294 static int cfg80211_wext_giwrate(struct net_device *dev, ··· 1261 1319 if (err) 1262 1320 return err; 1263 1321 1264 - wiphy_lock(&rdev->wiphy); 1265 - err = rdev_get_station(rdev, dev, addr, &sinfo); 1266 - wiphy_unlock(&rdev->wiphy); 1322 + scoped_guard(wiphy, &rdev->wiphy) { 1323 + err = rdev_get_station(rdev, dev, addr, &sinfo); 1324 + } 1267 1325 if (err) 1268 1326 return err; 1269 1327 ··· 1362 1420 struct sockaddr *ap_addr = &wrqu->ap_addr; 1363 1421 struct wireless_dev *wdev = dev->ieee80211_ptr; 1364 1422 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1365 - int ret; 1366 1423 1367 - wiphy_lock(&rdev->wiphy); 1424 + guard(wiphy)(&rdev->wiphy); 1425 + 1368 1426 switch (wdev->iftype) { 1369 1427 case NL80211_IFTYPE_ADHOC: 1370 - ret = cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); 1371 - break; 1428 + return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); 1372 1429 case NL80211_IFTYPE_STATION: 1373 - ret = cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); 1374 - break; 1430 + return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); 1375 1431 default: 1376 - ret = -EOPNOTSUPP; 1377 - break; 1432 + return -EOPNOTSUPP; 1378 1433 } 1379 - wiphy_unlock(&rdev->wiphy); 1380 - 1381 - return ret; 1382 1434 } 1383 1435 1384 1436 static int cfg80211_wext_giwap(struct net_device *dev, ··· 1382 1446 struct sockaddr *ap_addr = &wrqu->ap_addr; 1383 1447 struct wireless_dev *wdev = dev->ieee80211_ptr; 1384 1448 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1385 - int ret; 1386 1449 1387 - wiphy_lock(&rdev->wiphy); 1450 + guard(wiphy)(&rdev->wiphy); 1451 + 1388 1452 switch (wdev->iftype) { 1389 1453 case NL80211_IFTYPE_ADHOC: 1390 - ret = cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); 1391 - break; 1454 + return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); 1392 1455 case NL80211_IFTYPE_STATION: 1393 - ret = cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); 1394 - break; 1456 + return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); 1395 1457 default: 1396 - ret = -EOPNOTSUPP; 1397 - break; 1458 + return -EOPNOTSUPP; 1398 1459 } 1399 - wiphy_unlock(&rdev->wiphy); 1400 - 1401 - return ret; 1402 1460 } 1403 1461 1404 1462 static int cfg80211_wext_siwessid(struct net_device *dev, ··· 1402 1472 struct iw_point *data = &wrqu->data; 1403 1473 struct wireless_dev *wdev = dev->ieee80211_ptr; 1404 1474 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1405 - int ret; 1406 1475 1407 - wiphy_lock(&rdev->wiphy); 1476 + guard(wiphy)(&rdev->wiphy); 1477 + 1408 1478 switch (wdev->iftype) { 1409 1479 case NL80211_IFTYPE_ADHOC: 1410 - ret = cfg80211_ibss_wext_siwessid(dev, info, data, ssid); 1411 - break; 1480 + return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); 1412 1481 case NL80211_IFTYPE_STATION: 1413 - ret = cfg80211_mgd_wext_siwessid(dev, info, data, ssid); 1414 - break; 1482 + return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); 1415 1483 default: 1416 - ret = -EOPNOTSUPP; 1417 - break; 1484 + return -EOPNOTSUPP; 1418 1485 } 1419 - wiphy_unlock(&rdev->wiphy); 1420 - 1421 - return ret; 1422 1486 } 1423 1487 1424 1488 static int cfg80211_wext_giwessid(struct net_device *dev, ··· 1422 1498 struct iw_point *data = &wrqu->data; 1423 1499 struct wireless_dev *wdev = dev->ieee80211_ptr; 1424 1500 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1425 - int ret; 1426 1501 1427 1502 data->flags = 0; 1428 1503 data->length = 0; 1429 1504 1430 - wiphy_lock(&rdev->wiphy); 1505 + guard(wiphy)(&rdev->wiphy); 1506 + 1431 1507 switch (wdev->iftype) { 1432 1508 case NL80211_IFTYPE_ADHOC: 1433 - ret = cfg80211_ibss_wext_giwessid(dev, info, data, ssid); 1434 - break; 1509 + return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); 1435 1510 case NL80211_IFTYPE_STATION: 1436 - ret = cfg80211_mgd_wext_giwessid(dev, info, data, ssid); 1437 - break; 1511 + return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); 1438 1512 default: 1439 - ret = -EOPNOTSUPP; 1440 - break; 1513 + return -EOPNOTSUPP; 1441 1514 } 1442 - wiphy_unlock(&rdev->wiphy); 1443 - 1444 - return ret; 1445 1515 } 1446 1516 1447 1517 static int cfg80211_wext_siwpmksa(struct net_device *dev, ··· 1446 1528 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1447 1529 struct cfg80211_pmksa cfg_pmksa; 1448 1530 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra; 1449 - int ret; 1450 1531 1451 1532 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa)); 1452 1533 ··· 1455 1538 cfg_pmksa.bssid = pmksa->bssid.sa_data; 1456 1539 cfg_pmksa.pmkid = pmksa->pmkid; 1457 1540 1458 - wiphy_lock(&rdev->wiphy); 1541 + guard(wiphy)(&rdev->wiphy); 1542 + 1459 1543 switch (pmksa->cmd) { 1460 1544 case IW_PMKSA_ADD: 1461 - if (!rdev->ops->set_pmksa) { 1462 - ret = -EOPNOTSUPP; 1463 - break; 1464 - } 1545 + if (!rdev->ops->set_pmksa) 1546 + return -EOPNOTSUPP; 1465 1547 1466 - ret = rdev_set_pmksa(rdev, dev, &cfg_pmksa); 1467 - break; 1548 + return rdev_set_pmksa(rdev, dev, &cfg_pmksa); 1468 1549 case IW_PMKSA_REMOVE: 1469 - if (!rdev->ops->del_pmksa) { 1470 - ret = -EOPNOTSUPP; 1471 - break; 1472 - } 1550 + if (!rdev->ops->del_pmksa) 1551 + return -EOPNOTSUPP; 1473 1552 1474 - ret = rdev_del_pmksa(rdev, dev, &cfg_pmksa); 1475 - break; 1553 + return rdev_del_pmksa(rdev, dev, &cfg_pmksa); 1476 1554 case IW_PMKSA_FLUSH: 1477 - if (!rdev->ops->flush_pmksa) { 1478 - ret = -EOPNOTSUPP; 1479 - break; 1480 - } 1555 + if (!rdev->ops->flush_pmksa) 1556 + return -EOPNOTSUPP; 1481 1557 1482 - ret = rdev_flush_pmksa(rdev, dev); 1483 - break; 1558 + return rdev_flush_pmksa(rdev, dev); 1484 1559 default: 1485 - ret = -EOPNOTSUPP; 1486 - break; 1560 + return -EOPNOTSUPP; 1487 1561 } 1488 - wiphy_unlock(&rdev->wiphy); 1489 - 1490 - return ret; 1491 1562 } 1492 1563 1493 1564 static const iw_handler cfg80211_handlers[] = {
+15 -28
net/wireless/wext-sme.c
··· 302 302 struct iw_point *data = &wrqu->data; 303 303 struct wireless_dev *wdev = dev->ieee80211_ptr; 304 304 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 305 + int ie_len = data->length; 305 306 u8 *ie = extra; 306 - int ie_len = data->length, err; 307 307 308 308 if (wdev->iftype != NL80211_IFTYPE_STATION) 309 309 return -EOPNOTSUPP; ··· 311 311 if (!ie_len) 312 312 ie = NULL; 313 313 314 - wiphy_lock(wdev->wiphy); 314 + guard(wiphy)(wdev->wiphy); 315 315 316 316 /* no change */ 317 - err = 0; 318 317 if (wdev->wext.ie_len == ie_len && 319 318 memcmp(wdev->wext.ie, ie, ie_len) == 0) 320 - goto out; 319 + return 0; 321 320 322 321 if (ie_len) { 323 322 ie = kmemdup(extra, ie_len, GFP_KERNEL); 324 - if (!ie) { 325 - err = -ENOMEM; 326 - goto out; 327 - } 328 - } else 323 + if (!ie) 324 + return -ENOMEM; 325 + } else { 329 326 ie = NULL; 327 + } 330 328 331 329 kfree(wdev->wext.ie); 332 330 wdev->wext.ie = ie; 333 331 wdev->wext.ie_len = ie_len; 334 332 335 - if (wdev->conn) { 336 - err = cfg80211_disconnect(rdev, dev, 337 - WLAN_REASON_DEAUTH_LEAVING, false); 338 - if (err) 339 - goto out; 340 - } 333 + if (wdev->conn) 334 + return cfg80211_disconnect(rdev, dev, 335 + WLAN_REASON_DEAUTH_LEAVING, false); 341 336 342 337 /* userspace better not think we'll reconnect */ 343 - err = 0; 344 - out: 345 - wiphy_unlock(wdev->wiphy); 346 - return err; 338 + return 0; 347 339 } 348 340 349 341 int cfg80211_wext_siwmlme(struct net_device *dev, ··· 345 353 struct wireless_dev *wdev = dev->ieee80211_ptr; 346 354 struct iw_mlme *mlme = (struct iw_mlme *)extra; 347 355 struct cfg80211_registered_device *rdev; 348 - int err; 349 356 350 357 if (!wdev) 351 358 return -EOPNOTSUPP; ··· 357 366 if (mlme->addr.sa_family != ARPHRD_ETHER) 358 367 return -EINVAL; 359 368 360 - wiphy_lock(&rdev->wiphy); 369 + guard(wiphy)(&rdev->wiphy); 370 + 361 371 switch (mlme->cmd) { 362 372 case IW_MLME_DEAUTH: 363 373 case IW_MLME_DISASSOC: 364 - err = cfg80211_disconnect(rdev, dev, mlme->reason_code, true); 365 - break; 374 + return cfg80211_disconnect(rdev, dev, mlme->reason_code, true); 366 375 default: 367 - err = -EOPNOTSUPP; 368 - break; 376 + return -EOPNOTSUPP; 369 377 } 370 - wiphy_unlock(&rdev->wiphy); 371 - 372 - return err; 373 378 }