[PATCH 2/5] wifi: mt76: mt7921: refactor CLC support check flow

Sean Wang sean.wang at kernel.org
Mon Feb 23 14:41:34 PST 2026


HI, JB

On Mon, Feb 23, 2026 at 1:40 AM JB Tsai <jb.tsai at mediatek.com> wrote:
>
> Move the disable_clc module parameter to regd.c and introduce
> mt7925_regd_clc_supported() to centralize CLC support checks.

typo, s/7925/7921/

>
> Signed-off-by: JB Tsai <jb.tsai at mediatek.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7921/mcu.c  | 14 ++++++++------
>  drivers/net/wireless/mediatek/mt76/mt7921/regd.c | 13 +++++++++++++
>  drivers/net/wireless/mediatek/mt76/mt7921/regd.h |  1 +
>  3 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
> index 8442dbd2ee23..1e2afa736cdf 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
> @@ -4,6 +4,7 @@
>  #include <linux/fs.h>
>  #include <linux/firmware.h>
>  #include "mt7921.h"
> +#include "regd.h"
>  #include "mcu.h"
>  #include "../mt76_connac2_mac.h"
>  #include "../mt792x_trace.h"
> @@ -11,10 +12,6 @@
>  #define MT_STA_BFER                    BIT(0)
>  #define MT_STA_BFEE                    BIT(1)
>
> -static bool mt7921_disable_clc;
> -module_param_named(disable_clc, mt7921_disable_clc, bool, 0644);
> -MODULE_PARM_DESC(disable_clc, "disable CLC support");
> -
>  int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
>                               struct sk_buff *skb, int seq)
>  {
> @@ -422,8 +419,7 @@ static int mt7921_load_clc(struct mt792x_dev *dev, const char *fw_name)
>         u8 *clc_base = NULL, hw_encap = 0;
>
>         dev->phy.clc_chan_conf = 0xff;
> -       if (mt7921_disable_clc ||
> -           mt76_is_usb(&dev->mt76))
> +       if (!mt7921_regd_clc_supported(dev))
>                 return 0;
>
>         if (mt76_is_mmio(&dev->mt76)) {
> @@ -470,6 +466,9 @@ static int mt7921_load_clc(struct mt792x_dev *dev, const char *fw_name)
>         for (offset = 0; offset < len; offset += le32_to_cpu(clc->len)) {
>                 clc = (const struct mt7921_clc *)(clc_base + offset);
>
> +               if (clc->idx >= ARRAY_SIZE(phy->clc))
> +                       break;
> +

I’d keep the refactor logic-preserving. This bounds check is a
correctness fix (prevents OOB on phy->clc[clc->idx])
so please send it as a separate hardening patch and describe the failure and fix
Also, ARRAY_SIZE() is for compile-time arrays only if phy->clc were a
pointer, it would be invalid/misleading I guess.

>                 /* do not init buf again if chip reset triggered */
>                 if (phy->clc[clc->idx])
>                         continue;
> @@ -1403,6 +1402,9 @@ int mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
>         struct mt792x_phy *phy = (struct mt792x_phy *)&dev->phy;
>         int i, ret;
>
> +       if (!ARRAY_SIZE(phy->clc))
> +               return -ESRCH;
> +

Ditto,  to keep the refactor logic-preserving, send it as a separate
hardening patch and describe the failure and fix and also
!ARRAY_SIZE(phy->clc) isn’t a meaningful runtime check I guess.

>         /* submit all clc config */
>         for (i = 0; i < ARRAY_SIZE(phy->clc); i++) {
>                 ret = __mt7921_mcu_set_clc(dev, alpha2, env_cap,
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c
> index 6e6c81189222..70440ab8ba82 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c
> @@ -7,6 +7,19 @@
>  #include "regd.h"
>  #include "mcu.h"
>
> +static bool mt7921_disable_clc;
> +module_param_named(disable_clc, mt7921_disable_clc, bool, 0644);
> +MODULE_PARM_DESC(disable_clc, "disable CLC support");
> +

should we explicitly include <linux/moduleparam.h> ?

> +bool mt7921_regd_clc_supported(struct mt792x_dev *dev)
> +{
> +       if (mt7921_disable_clc ||
> +           mt76_is_usb(&dev->mt76))
> +               return false;
> +
> +       return true;
> +}
> +
>  static void
>  mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev)
>  {
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regd.h b/drivers/net/wireless/mediatek/mt76/mt7921/regd.h
> index 0ba6161e1919..74bc2fdd532c 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/regd.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/regd.h
> @@ -9,5 +9,6 @@
>  void mt7921_regd_update(struct mt792x_dev *dev);
>  void mt7921_regd_notifier(struct wiphy *wiphy,
>                           struct regulatory_request *request);
> +bool mt7921_regd_clc_supported(struct mt792x_dev *dev);
>
>  #endif
> --
> 2.45.2
>
>



More information about the Linux-mediatek mailing list