iwlwifi: size firmware flags memory correctly
authorJohannes Berg <johannes.berg@intel.com>
Wed, 16 Sep 2015 10:21:32 +0000 (12:21 +0200)
committerLuca Coelho <luciano.coelho@intel.com>
Mon, 5 Oct 2015 11:33:33 +0000 (14:33 +0300)
Instead of relying on a hard-coded constant of a maximum of 64 API and
capability bits, add a new enum value after the others that will then
always track the number of used bits in the API/capabilities. We thus
no longer need to maintain the maximum number, and on 32-bit platforms
even (currently) reduce the number of bits kept in memory.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/iwlwifi/iwl-drv.c
drivers/net/wireless/iwlwifi/iwl-fw-file.h
drivers/net/wireless/iwlwifi/iwl-fw.h

index a86aa5b..463cadf 100644 (file)
@@ -450,7 +450,7 @@ static int iwl_set_ucode_api_flags(struct iwl_drv *drv, const u8 *data,
        u32 api_flags = le32_to_cpu(ucode_api->api_flags);
        int i;
 
-       if (api_index >= IWL_API_MAX_BITS / 32) {
+       if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_API, 32)) {
                IWL_ERR(drv, "api_index larger than supported by driver\n");
                /* don't return an error so we can load FW that has more bits */
                return 0;
@@ -472,7 +472,7 @@ static int iwl_set_ucode_capabilities(struct iwl_drv *drv, const u8 *data,
        u32 api_flags = le32_to_cpu(ucode_capa->api_capa);
        int i;
 
-       if (api_index >= IWL_CAPABILITIES_MAX_BITS / 32) {
+       if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_CAPA, 32)) {
                IWL_ERR(drv, "api_index larger than supported by driver\n");
                /* don't return an error so we can load FW that has more bits */
                return 0;
index 352d245..72ddd4a 100644 (file)
@@ -254,6 +254,8 @@ typedef unsigned int __bitwise__ iwl_ucode_tlv_api_t;
  *     instead of 3.
  * @IWL_UCODE_TLV_API_TX_POWER_CHAIN: TX power API has larger command size
  *     (command version 3) that supports per-chain limits
+ *
+ * @NUM_IWL_UCODE_TLV_API: number of bits used
  */
 enum iwl_ucode_tlv_api {
        IWL_UCODE_TLV_API_BT_COEX_SPLIT         = (__force iwl_ucode_tlv_api_t)3,
@@ -264,6 +266,12 @@ enum iwl_ucode_tlv_api {
        IWL_UCODE_TLV_API_NEW_VERSION           = (__force iwl_ucode_tlv_api_t)20,
        IWL_UCODE_TLV_API_EXT_SCAN_PRIORITY     = (__force iwl_ucode_tlv_api_t)24,
        IWL_UCODE_TLV_API_TX_POWER_CHAIN        = (__force iwl_ucode_tlv_api_t)27,
+
+       NUM_IWL_UCODE_TLV_API
+#ifdef __CHECKER__
+               /* sparse says it cannot increment the previous enum member */
+               = 128
+#endif
 };
 
 typedef unsigned int __bitwise__ iwl_ucode_tlv_capa_t;
@@ -298,6 +306,8 @@ typedef unsigned int __bitwise__ iwl_ucode_tlv_capa_t;
  *     is supported.
  * @IWL_UCODE_TLV_CAPA_BT_COEX_RRC: supports BT Coex RRC
  * @IWL_UCODE_TLV_CAPA_GSCAN_SUPPORT: supports gscan
+ *
+ * @NUM_IWL_UCODE_TLV_CAPA: number of bits used
  */
 enum iwl_ucode_tlv_capa {
        IWL_UCODE_TLV_CAPA_D0I3_SUPPORT                 = (__force iwl_ucode_tlv_capa_t)0,
@@ -320,6 +330,12 @@ enum iwl_ucode_tlv_capa {
        IWL_UCODE_TLV_CAPA_LAR_MULTI_MCC                = (__force iwl_ucode_tlv_capa_t)29,
        IWL_UCODE_TLV_CAPA_BT_COEX_RRC                  = (__force iwl_ucode_tlv_capa_t)30,
        IWL_UCODE_TLV_CAPA_GSCAN_SUPPORT                = (__force iwl_ucode_tlv_capa_t)31,
+
+       NUM_IWL_UCODE_TLV_CAPA
+#ifdef __CHECKER__
+               /* sparse says it cannot increment the previous enum member */
+               = 128
+#endif
 };
 
 /* The default calibrate table size if not specified by firmware file */
@@ -330,9 +346,6 @@ enum iwl_ucode_tlv_capa {
 /* The default max probe length if not specified by the firmware file */
 #define IWL_DEFAULT_MAX_PROBE_LENGTH   200
 
-#define IWL_API_MAX_BITS               64
-#define IWL_CAPABILITIES_MAX_BITS      64
-
 /*
  * For 16.0 uCode and above, there is no differentiation between sections,
  * just an offset to the HW address.
index 45e7321..84ec0ce 100644 (file)
@@ -105,8 +105,8 @@ struct iwl_ucode_capabilities {
        u32 n_scan_channels;
        u32 standard_phy_calibration_size;
        u32 flags;
-       unsigned long _api[BITS_TO_LONGS(IWL_API_MAX_BITS)];
-       unsigned long _capa[BITS_TO_LONGS(IWL_CAPABILITIES_MAX_BITS)];
+       unsigned long _api[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_API)];
+       unsigned long _capa[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_CAPA)];
 };
 
 static inline bool