From: Johannes Berg Date: Thu, 28 Aug 2025 08:25:47 +0000 (+0300) Subject: wifi: iwlwifi: uefi: remove runtime check of constant values X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f53f2bd8fc5f7d986b676a3f80505ba4d6b0b311;p=users%2Fhch%2Fmisc.git wifi: iwlwifi: uefi: remove runtime check of constant values 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 Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20250828111032.cc3c17327ea2.I99c7175be1f72f29b154454fc24978daafad476f@changeid --- diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 48126ec6b94b..44c7c565d1c6 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -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,