Move the growing parameter list to a structure for the interface combination check and iteration functions in cfg80211 and mac80211 to make the code easier to understand.
Unified · Split
| @@ -414,23 +414,24 @@ static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, · 413 unmodified lines | ||
| 414 | 414 | struct brcmf_cfg80211_vif *vif, |
| 415 | 415 | enum nl80211_iftype new_type) |
| 416 | 416 | { |
| 417 | − int iftype_num[NUM_NL80211_IFTYPES]; | |
| 418 | 417 | struct brcmf_cfg80211_vif *pos; |
| 419 | 418 | bool check_combos = false; |
| 420 | 419 | int ret = 0; |
| 420 | + struct iface_combination_params params = { | |
| 421 | + .num_different_channels = 1, | |
| 422 | + }; | |
| 421 | 423 | |
| 422 | − memset(&iftype_num[0], 0, sizeof(iftype_num)); | |
| 423 | 424 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 424 | 425 | if (pos == vif) { |
| 425 | − iftype_num[new_type]++; | |
| 426 | + params.iftype_num[new_type]++; | |
| 426 | 427 | } else { |
| 427 | 428 | /* concurrent interfaces so need check combinations */ |
| 428 | 429 | check_combos = true; |
| 429 | − iftype_num[pos->wdev.iftype]++; | |
| 430 | + params.iftype_num[pos->wdev.iftype]++; | |
| 430 | 431 | } |
| 431 | 432 | |
| 432 | 433 | if (check_combos) |
| 433 | − ret = cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); | |
| 434 | + ret = cfg80211_check_combinations(cfg->wiphy, ¶ms); | |
| 434 | 435 | |
| 435 | 436 | return ret; |
| 436 | 437 | } |
| @@ -438,15 +439,16 @@ static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, · 1 unmodified line | ||
| 438 | 439 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, |
| 439 | 440 | enum nl80211_iftype new_type) |
| 440 | 441 | { |
| 441 | − int iftype_num[NUM_NL80211_IFTYPES]; | |
| 442 | 442 | struct brcmf_cfg80211_vif *pos; |
| 443 | + struct iface_combination_params params = { | |
| 444 | + .num_different_channels = 1, | |
| 445 | + }; | |
| 443 | 446 | |
| 444 | − memset(&iftype_num[0], 0, sizeof(iftype_num)); | |
| 445 | 447 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 446 | − iftype_num[pos->wdev.iftype]++; | |
| 448 | + params.iftype_num[pos->wdev.iftype]++; | |
| 447 | 449 | |
| 448 | − iftype_num[new_type]++; | |
| 449 | − return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); | |
| 450 | + params.iftype_num[new_type]++; | |
| 451 | + return cfg80211_check_combinations(cfg->wiphy, ¶ms); | |
| 450 | 452 | } |
| 451 | 453 | |
| 452 | 454 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| @@ -771,6 +771,26 @@ struct cfg80211_csa_settings { · 770 unmodified lines | ||
| 771 | 771 | u8 count; |
| 772 | 772 | }; |
| 773 | 773 | |
| 774 | +/** | |
| 775 | + * struct iface_combination_params - input parameters for interface combinations | |
| 776 | + * | |
| 777 | + * Used to pass interface combination parameters | |
| 778 | + * | |
| 779 | + * @num_different_channels: the number of different channels we want | |
| 780 | + * to use for verification | |
| 781 | + * @radar_detect: a bitmap where each bit corresponds to a channel | |
| 782 | + * width where radar detection is needed, as in the definition of | |
| 783 | + * &struct ieee80211_iface_combination.@radar_detect_widths | |
| 784 | + * @iftype_num: array with the number of interfaces of each interface | |
| 785 | + * type. The index is the interface type as specified in &enum | |
| 786 | + * nl80211_iftype. | |
| 787 | + */ | |
| 788 | +struct iface_combination_params { | |
| 789 | + int num_different_channels; | |
| 790 | + u8 radar_detect; | |
| 791 | + int iftype_num[NUM_NL80211_IFTYPES]; | |
| 792 | +}; | |
| 793 | + | |
| 774 | 794 | /** |
| 775 | 795 | * enum station_parameters_apply_mask - station parameter values to apply |
| 776 | 796 | * @STATION_PARAM_APPLY_UAPSD: apply new uAPSD parameters (uapsd_queues, max_sp) |
| @@ -5575,36 +5595,20 @@ unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy); · 4798 unmodified lines | ||
| 5575 | 5595 | * cfg80211_check_combinations - check interface combinations |
| 5576 | 5596 | * |
| 5577 | 5597 | * @wiphy: the wiphy |
| 5578 | − * @num_different_channels: the number of different channels we want | |
| 5579 | − * to use for verification | |
| 5580 | − * @radar_detect: a bitmap where each bit corresponds to a channel | |
| 5581 | − * width where radar detection is needed, as in the definition of | |
| 5582 | − * &struct ieee80211_iface_combination.@radar_detect_widths | |
| 5583 | − * @iftype_num: array with the numbers of interfaces of each interface | |
| 5584 | − * type. The index is the interface type as specified in &enum | |
| 5585 | − * nl80211_iftype. | |
| 5598 | + * @params: the interface combinations parameter | |
| 5586 | 5599 | * |
| 5587 | 5600 | * This function can be called by the driver to check whether a |
| 5588 | 5601 | * combination of interfaces and their types are allowed according to |
| 5589 | 5602 | * the interface combinations. |
| 5590 | 5603 | */ |
| 5591 | 5604 | int cfg80211_check_combinations(struct wiphy *wiphy, |
| 5592 | − const int num_different_channels, | |
| 5593 | − const u8 radar_detect, | |
| 5594 | − const int iftype_num[NUM_NL80211_IFTYPES]); | |
| 5605 | + struct iface_combination_params *params); | |
| 5595 | 5606 | |
| 5596 | 5607 | /** |
| 5597 | 5608 | * cfg80211_iter_combinations - iterate over matching combinations |
| 5598 | 5609 | * |
| 5599 | 5610 | * @wiphy: the wiphy |
| 5600 | − * @num_different_channels: the number of different channels we want | |
| 5601 | − * to use for verification | |
| 5602 | − * @radar_detect: a bitmap where each bit corresponds to a channel | |
| 5603 | − * width where radar detection is needed, as in the definition of | |
| 5604 | − * &struct ieee80211_iface_combination.@radar_detect_widths | |
| 5605 | − * @iftype_num: array with the numbers of interfaces of each interface | |
| 5606 | − * type. The index is the interface type as specified in &enum | |
| 5607 | − * nl80211_iftype. | |
| 5611 | + * @params: the interface combinations parameter | |
| 5608 | 5612 | * @iter: function to call for each matching combination |
| 5609 | 5613 | * @data: pointer to pass to iter function |
| 5610 | 5614 | * |
| @@ -5613,9 +5617,7 @@ int cfg80211_check_combinations(struct wiphy *wiphy, · 2 unmodified lines | ||
| 5613 | 5617 | * purposes. |
| 5614 | 5618 | */ |
| 5615 | 5619 | int cfg80211_iter_combinations(struct wiphy *wiphy, |
| 5616 | − const int num_different_channels, | |
| 5617 | − const u8 radar_detect, | |
| 5618 | − const int iftype_num[NUM_NL80211_IFTYPES], | |
| 5620 | + struct iface_combination_params *params, | |
| 5619 | 5621 | void (*iter)(const struct ieee80211_iface_combination *c, |
| 5620 | 5622 | void *data), |
| 5621 | 5623 | void *data); |
| @@ -3308,10 +3308,11 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 3307 unmodified lines | ||
| 3308 | 3308 | struct ieee80211_local *local = sdata->local; |
| 3309 | 3309 | struct ieee80211_sub_if_data *sdata_iter; |
| 3310 | 3310 | enum nl80211_iftype iftype = sdata->wdev.iftype; |
| 3311 | − int num[NUM_NL80211_IFTYPES]; | |
| 3312 | 3311 | struct ieee80211_chanctx *ctx; |
| 3313 | − int num_different_channels = 0; | |
| 3314 | 3312 | int total = 1; |
| 3313 | + struct iface_combination_params params = { | |
| 3314 | + .radar_detect = radar_detect, | |
| 3315 | + }; | |
| 3315 | 3316 | |
| 3316 | 3317 | lockdep_assert_held(&local->chanctx_mtx); |
| 3317 | 3318 | |
| @@ -3322,9 +3323,6 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 4 unmodified lines | ||
| 3322 | 3323 | !chandef->chan)) |
| 3323 | 3324 | return -EINVAL; |
| 3324 | 3325 | |
| 3325 | − if (chandef) | |
| 3326 | − num_different_channels = 1; | |
| 3327 | − | |
| 3328 | 3326 | if (WARN_ON(iftype >= NUM_NL80211_IFTYPES)) |
| 3329 | 3327 | return -EINVAL; |
| 3330 | 3328 | |
| @@ -3335,24 +3333,26 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 4 unmodified lines | ||
| 3335 | 3333 | return 0; |
| 3336 | 3334 | } |
| 3337 | 3335 | |
| 3338 | − memset(num, 0, sizeof(num)); | |
| 3336 | + if (chandef) | |
| 3337 | + params.num_different_channels = 1; | |
| 3339 | 3338 | |
| 3340 | 3339 | if (iftype != NL80211_IFTYPE_UNSPECIFIED) |
| 3341 | − num[iftype] = 1; | |
| 3340 | + params.iftype_num[iftype] = 1; | |
| 3342 | 3341 | |
| 3343 | 3342 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
| 3344 | 3343 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) |
| 3345 | 3344 | continue; |
| 3346 | − radar_detect |= ieee80211_chanctx_radar_detect(local, ctx); | |
| 3345 | + params.radar_detect |= | |
| 3346 | + ieee80211_chanctx_radar_detect(local, ctx); | |
| 3347 | 3347 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) { |
| 3348 | − num_different_channels++; | |
| 3348 | + params.num_different_channels++; | |
| 3349 | 3349 | continue; |
| 3350 | 3350 | } |
| 3351 | 3351 | if (chandef && chanmode == IEEE80211_CHANCTX_SHARED && |
| 3352 | 3352 | cfg80211_chandef_compatible(chandef, |
| 3353 | 3353 | &ctx->conf.def)) |
| 3354 | 3354 | continue; |
| 3355 | − num_different_channels++; | |
| 3355 | + params.num_different_channels++; | |
| 3356 | 3356 | } |
| 3357 | 3357 | |
| 3358 | 3358 | list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) { |
| @@ -3365,16 +3365,14 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 6 unmodified lines | ||
| 3365 | 3365 | local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype)) |
| 3366 | 3366 | continue; |
| 3367 | 3367 | |
| 3368 | − num[wdev_iter->iftype]++; | |
| 3368 | + params.iftype_num[wdev_iter->iftype]++; | |
| 3369 | 3369 | total++; |
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | − if (total == 1 && !radar_detect) | |
| 3372 | + if (total == 1 && !params.radar_detect) | |
| 3373 | 3373 | return 0; |
| 3374 | 3374 | |
| 3375 | − return cfg80211_check_combinations(local->hw.wiphy, | |
| 3376 | − num_different_channels, | |
| 3377 | − radar_detect, num); | |
| 3375 | + return cfg80211_check_combinations(local->hw.wiphy, ¶ms); | |
| 3378 | 3376 | } |
| 3379 | 3377 | |
| 3380 | 3378 | static void |
| @@ -3390,12 +3388,10 @@ ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c, · 9 unmodified lines | ||
| 3390 | 3388 | int ieee80211_max_num_channels(struct ieee80211_local *local) |
| 3391 | 3389 | { |
| 3392 | 3390 | struct ieee80211_sub_if_data *sdata; |
| 3393 | − int num[NUM_NL80211_IFTYPES] = {}; | |
| 3394 | 3391 | struct ieee80211_chanctx *ctx; |
| 3395 | − int num_different_channels = 0; | |
| 3396 | − u8 radar_detect = 0; | |
| 3397 | 3392 | u32 max_num_different_channels = 1; |
| 3398 | 3393 | int err; |
| 3394 | + struct iface_combination_params params = {0}; | |
| 3399 | 3395 | |
| 3400 | 3396 | lockdep_assert_held(&local->chanctx_mtx); |
| 3401 | 3397 | |
| @@ -3403,17 +3399,17 @@ int ieee80211_max_num_channels(struct ieee80211_local *local) · 1 unmodified line | ||
| 3403 | 3399 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) |
| 3404 | 3400 | continue; |
| 3405 | 3401 | |
| 3406 | − num_different_channels++; | |
| 3402 | + params.num_different_channels++; | |
| 3407 | 3403 | |
| 3408 | − radar_detect |= ieee80211_chanctx_radar_detect(local, ctx); | |
| 3404 | + params.radar_detect |= | |
| 3405 | + ieee80211_chanctx_radar_detect(local, ctx); | |
| 3409 | 3406 | } |
| 3410 | 3407 | |
| 3411 | 3408 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 3412 | − num[sdata->wdev.iftype]++; | |
| 3409 | + params.iftype_num[sdata->wdev.iftype]++; | |
| 3413 | 3410 | |
| 3414 | − err = cfg80211_iter_combinations(local->hw.wiphy, | |
| 3415 | − num_different_channels, radar_detect, | |
| 3416 | − num, ieee80211_iter_max_chans, | |
| 3411 | + err = cfg80211_iter_combinations(local->hw.wiphy, ¶ms, | |
| 3412 | + ieee80211_iter_max_chans, | |
| 3417 | 3413 | &max_num_different_channels); |
| 3418 | 3414 | if (err < 0) |
| 3419 | 3415 | return err; |
| @@ -1580,9 +1580,7 @@ int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev, · 1579 unmodified lines | ||
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | int cfg80211_iter_combinations(struct wiphy *wiphy, |
| 1583 | − const int num_different_channels, | |
| 1584 | − const u8 radar_detect, | |
| 1585 | − const int iftype_num[NUM_NL80211_IFTYPES], | |
| 1583 | + struct iface_combination_params *params, | |
| 1586 | 1584 | void (*iter)(const struct ieee80211_iface_combination *c, |
| 1587 | 1585 | void *data), |
| 1588 | 1586 | void *data) |
| @@ -1593,7 +1591,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 4 unmodified lines | ||
| 1593 | 1591 | int num_interfaces = 0; |
| 1594 | 1592 | u32 used_iftypes = 0; |
| 1595 | 1593 | |
| 1596 | − if (radar_detect) { | |
| 1594 | + if (params->radar_detect) { | |
| 1597 | 1595 | rcu_read_lock(); |
| 1598 | 1596 | regdom = rcu_dereference(cfg80211_regdomain); |
| 1599 | 1597 | if (regdom) |
| @@ -1602,8 +1600,8 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 2 unmodified lines | ||
| 1602 | 1600 | } |
| 1603 | 1601 | |
| 1604 | 1602 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { |
| 1605 | − num_interfaces += iftype_num[iftype]; | |
| 1606 | − if (iftype_num[iftype] > 0 && | |
| 1603 | + num_interfaces += params->iftype_num[iftype]; | |
| 1604 | + if (params->iftype_num[iftype] > 0 && | |
| 1607 | 1605 | !(wiphy->software_iftypes & BIT(iftype))) |
| 1608 | 1606 | used_iftypes |= BIT(iftype); |
| 1609 | 1607 | } |
| @@ -1617,7 +1615,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 7 unmodified lines | ||
| 1617 | 1615 | |
| 1618 | 1616 | if (num_interfaces > c->max_interfaces) |
| 1619 | 1617 | continue; |
| 1620 | − if (num_different_channels > c->num_different_channels) | |
| 1618 | + if (params->num_different_channels > c->num_different_channels) | |
| 1621 | 1619 | continue; |
| 1622 | 1620 | |
| 1623 | 1621 | limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits, |
| @@ -1632,16 +1630,17 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 8 unmodified lines | ||
| 1632 | 1630 | all_iftypes |= limits[j].types; |
| 1633 | 1631 | if (!(limits[j].types & BIT(iftype))) |
| 1634 | 1632 | continue; |
| 1635 | − if (limits[j].max < iftype_num[iftype]) | |
| 1633 | + if (limits[j].max < params->iftype_num[iftype]) | |
| 1636 | 1634 | goto cont; |
| 1637 | − limits[j].max -= iftype_num[iftype]; | |
| 1635 | + limits[j].max -= params->iftype_num[iftype]; | |
| 1638 | 1636 | } |
| 1639 | 1637 | } |
| 1640 | 1638 | |
| 1641 | − if (radar_detect != (c->radar_detect_widths & radar_detect)) | |
| 1639 | + if (params->radar_detect != | |
| 1640 | + (c->radar_detect_widths & params->radar_detect)) | |
| 1642 | 1641 | goto cont; |
| 1643 | 1642 | |
| 1644 | − if (radar_detect && c->radar_detect_regions && | |
| 1643 | + if (params->radar_detect && c->radar_detect_regions && | |
| 1645 | 1644 | !(c->radar_detect_regions & BIT(region))) |
| 1646 | 1645 | goto cont; |
| 1647 | 1646 | |
| @@ -1675,14 +1674,11 @@ cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c, · 27 unmodified lines | ||
| 1675 | 1674 | } |
| 1676 | 1675 | |
| 1677 | 1676 | int cfg80211_check_combinations(struct wiphy *wiphy, |
| 1678 | − const int num_different_channels, | |
| 1679 | − const u8 radar_detect, | |
| 1680 | − const int iftype_num[NUM_NL80211_IFTYPES]) | |
| 1677 | + struct iface_combination_params *params) | |
| 1681 | 1678 | { |
| 1682 | 1679 | int err, num = 0; |
| 1683 | 1680 | |
| 1684 | − err = cfg80211_iter_combinations(wiphy, num_different_channels, | |
| 1685 | − radar_detect, iftype_num, | |
| 1681 | + err = cfg80211_iter_combinations(wiphy, params, | |
| 1686 | 1682 | cfg80211_iter_sum_ifcombs, &num); |
| 1687 | 1683 | if (err) |
| 1688 | 1684 | return err; |