]> www.infradead.org Git - users/hch/misc.git/commitdiff
wifi: iwlwifi: uefi: remove runtime check of constant values
authorJohannes Berg <johannes.berg@intel.com>
Thu, 28 Aug 2025 08:25:47 +0000 (11:25 +0300)
committerMiri Korenblit <miriam.rachel.korenblit@intel.com>
Sun, 31 Aug 2025 11:39:25 +0000 (14:39 +0300)
There's no need to check an ARRAY_SIZE() at runtime, it's
already determined at build time, so could be a BUILD_BUG_ON.
However it's not that useful here since the array is defined
using UEFI_MAX_DSM_FUNCS, check DSM_FUNC_NUM_FUNCS instead to
ensure the array cannot be accessed out-of-band, i.e. ensure
the range check there is always good enough.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250828111032.cc3c17327ea2.I99c7175be1f72f29b154454fc24978daafad476f@changeid
drivers/net/wireless/intel/iwlwifi/fw/uefi.c

index 48126ec6b94bfd6d0dac79389ee73f4f5667e8c1..44c7c565d1c61d832d710a74cf02fdc1b89c6e64 100644 (file)
@@ -727,6 +727,8 @@ int iwl_uefi_get_dsm(struct iwl_fw_runtime *fwrt, enum iwl_dsm_funcs func,
        struct uefi_cnv_var_general_cfg *data;
        int ret = -EINVAL;
 
+       BUILD_BUG_ON(ARRAY_SIZE(data->functions) < DSM_FUNC_NUM_FUNCS);
+
        /* Not supported function index */
        if (func >= DSM_FUNC_NUM_FUNCS || func == 5)
                return -EOPNOTSUPP;
@@ -742,11 +744,6 @@ int iwl_uefi_get_dsm(struct iwl_fw_runtime *fwrt, enum iwl_dsm_funcs func,
                goto out;
        }
 
-       if (ARRAY_SIZE(data->functions) != UEFI_MAX_DSM_FUNCS) {
-               IWL_DEBUG_RADIO(fwrt, "Invalid size of DSM functions array\n");
-               goto out;
-       }
-
        *value = data->functions[func];
 
        IWL_DEBUG_RADIO(fwrt,