iwlwifi: Use common error handling code in five functions
Subsystems (2)
PATCH 1/1 iwlwifi: Use common error handling code in five functions
From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2024 10:22:20 +0100
The error code “-EINVAL” was set before the statement “goto out_free” multiple times in some function implementations.
Add jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was transformed by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
--- drivers/net/wireless/intel/iwlwifi/fw/acpi.c | 130 +++++++++---------- 1 file changed, 58 insertions(+), 72 deletions(-)
drivers/net/wireless/intel/iwlwifi/fw/acpi.c +58 -72
@@ -285,8 +285,7 @@ int iwl_acpi_get_tas_table(struct iwl_fw_runtime *fwrt, wifi_pkg->package.elements[1].type == ACPI_TYPE_INTEGER) { enabled = !!wifi_pkg->package.elements[1].integer.value; } else { - ret = -EINVAL ; - goto out_free; + goto out_e_inval; }if (!enabled) {
@@ -301,8 +300,7 @@ int iwl_acpi_get_tas_table(struct iwl_fw_runtime *fwrt, IWL_WTAS_BLACK_LIST_MAX) {IWL_DEBUG_RADIO (fwrt,"TAS invalid array size %llu\n" , wifi_pkg->package.elements[2 ].integer.value); - ret = -EINVAL ; - goto out_free; + goto out_e_inval; } block_list_size = wifi_pkg->package.elements[2 ].integer.value; tas_data->block_list_size =cpu_to_le32 (block_list_size);
@@ -316,8 +314,7 @@ int iwl_acpi_get_tas_table(struct iwl_fw_runtime *fwrt, ACPI_TYPE_INTEGER) {IWL_DEBUG_RADIO (fwrt,"TAS invalid array elem %d\n" ,3 + i); - ret = -EINVAL ; - goto out_free; + goto out_e_inval; } country = wifi_pkg->package.elements[3 + i].integer.value;
@@ -329,6 +326,10 @@ int iwl_acpi_get_tas_table(struct iwl_fw_runtime *fwrt, out_free:kfree (data);return ret; + +out_e_inval: + ret = -EINVAL ; + goto out_free; }int iwl_acpi_get_mcc (struct iwl_fw_runtime *fwrt,char *mcc)
@@ -474,10 +475,8 @@ int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt)ACPI_WRDS_WIFI_DATA_SIZE_REV2 , &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=2 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=2 ) + goto out_e_inval; num_chains =ACPI_SAR_NUM_CHAINS_REV2 ; num_sub_bands =ACPI_SAR_NUM_SUB_BANDS_REV2 ;
@@ -490,10 +489,8 @@ int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt)ACPI_WRDS_WIFI_DATA_SIZE_REV1 , &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=1 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=1 ) + goto out_e_inval; num_chains =ACPI_SAR_NUM_CHAINS_REV1 ; num_sub_bands =ACPI_SAR_NUM_SUB_BANDS_REV1 ;
@@ -506,10 +503,8 @@ int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt)ACPI_WRDS_WIFI_DATA_SIZE_REV0 , &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=0 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=0 ) + goto out_e_inval; num_chains =ACPI_SAR_NUM_CHAINS_REV0 ; num_sub_bands =ACPI_SAR_NUM_SUB_BANDS_REV0 ;
@@ -521,10 +516,8 @@ int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt) goto out_free; read_table: -if (wifi_pkg->package.elements[1 ].type !=ACPI_TYPE_INTEGER ) { - ret = -EINVAL ; - goto out_free; - } +if (wifi_pkg->package.elements[1 ].type !=ACPI_TYPE_INTEGER ) + goto out_e_inval;IWL_DEBUG_RADIO (fwrt,"Reading WRDS tbl_rev=%d\n" , tbl_rev);
@@ -543,6 +536,10 @@ int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt) out_free:kfree (data);return ret; + +out_e_inval: + ret = -EINVAL ; + goto out_free; }int iwl_acpi_get_ewrd_table (struct iwl_fw_runtime *fwrt)
@@ -562,10 +559,8 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt)ACPI_EWRD_WIFI_DATA_SIZE_REV2 , &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=2 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=2 ) + goto out_e_inval; num_chains =ACPI_SAR_NUM_CHAINS_REV2 ; num_sub_bands =ACPI_SAR_NUM_SUB_BANDS_REV2 ;
@@ -578,10 +573,8 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt)ACPI_EWRD_WIFI_DATA_SIZE_REV1 , &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=1 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=1 ) + goto out_e_inval; num_chains =ACPI_SAR_NUM_CHAINS_REV1 ; num_sub_bands =ACPI_SAR_NUM_SUB_BANDS_REV1 ;
@@ -594,10 +587,8 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt)ACPI_EWRD_WIFI_DATA_SIZE_REV0 , &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=0 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=0 ) + goto out_e_inval; num_chains =ACPI_SAR_NUM_CHAINS_REV0 ; num_sub_bands =ACPI_SAR_NUM_SUB_BANDS_REV0 ;
@@ -610,10 +601,8 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt) read_table:if (wifi_pkg->package.elements[1 ].type !=ACPI_TYPE_INTEGER || - wifi_pkg->package.elements[2 ].type !=ACPI_TYPE_INTEGER ) { - ret = -EINVAL ; - goto out_free; - } + wifi_pkg->package.elements[2 ].type !=ACPI_TYPE_INTEGER ) + goto out_e_inval; enabled = !!(wifi_pkg->package.elements[1 ].integer.value); n_profiles = wifi_pkg->package.elements[2 ].integer.value;
@@ -623,10 +612,8 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt)* from index 1, so the maximum value allowed here is * ACPI_SAR_PROFILES_NUM - 1. */ -if (n_profiles >=BIOS_SAR_MAX_PROFILE_NUM ) { - ret = -EINVAL ; - goto out_free; - } +if (n_profiles >=BIOS_SAR_MAX_PROFILE_NUM ) + goto out_e_inval;/* the tables start at element 3 */ pos =3 ;
@@ -651,6 +638,10 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt) out_free:kfree (data);return ret; + +out_e_inval: + ret = -EINVAL ; + goto out_free; }int iwl_acpi_get_wgds_table (struct iwl_fw_runtime *fwrt)
@@ -724,10 +715,9 @@ int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt) entry = &wifi_pkg->package.elements[entry_idx]; entry_idx++;if (entry->type !=ACPI_TYPE_INTEGER || - entry->integer.value > num_profiles) { - ret = -EINVAL ; - goto out_free; - } + entry->integer.value > num_profiles) + goto out_e_inval; + num_profiles = entry->integer.value;/*
@@ -736,10 +726,8 @@ int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt)* looking up in ACPI */ if (wifi_pkg->package.count != - hdr_size + profile_size * num_profiles) { - ret = -EINVAL ; - goto out_free; - } + hdr_size + profile_size * num_profiles) + goto out_e_inval; } goto read_table; }
@@ -769,10 +757,8 @@ int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt) entry = &wifi_pkg->package.elements[entry_idx]; entry_idx++;if (entry->type !=ACPI_TYPE_INTEGER || - entry->integer.value >U8_MAX ) { - ret = -EINVAL ; - goto out_free; - } + entry->integer.value >U8_MAX ) + goto out_e_inval; fwrt->geo_profiles[i].bands[j].max = entry->integer.value;
@@ -787,10 +773,8 @@ int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt) entry = &wifi_pkg->package.elements[entry_idx]; entry_idx++;if (entry->type !=ACPI_TYPE_INTEGER || - entry->integer.value >U8_MAX ) { - ret = -EINVAL ; - goto out_free; - } + entry->integer.value >U8_MAX ) + goto out_e_inval; fwrt->geo_profiles[i].bands[j].chains[k] = entry->integer.value;
@@ -805,6 +789,10 @@ int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt) out_free:kfree (data);return ret; + +out_e_inval: + ret = -EINVAL ; + goto out_free; }int iwl_acpi_get_ppag_table (struct iwl_fw_runtime *fwrt)
@@ -829,8 +817,7 @@ int iwl_acpi_get_ppag_table(struct iwl_fw_runtime *fwrt) tbl_rev); goto read_table; }else { - ret = -EINVAL ; - goto out_free; + goto out_e_inval; } }
@@ -839,10 +826,9 @@ int iwl_acpi_get_ppag_table(struct iwl_fw_runtime *fwrt) ACPI_PPAG_WIFI_DATA_SIZE_V1, &tbl_rev);if (!IS_ERR (wifi_pkg)) { -if (tbl_rev !=0 ) { - ret = -EINVAL ; - goto out_free; - } +if (tbl_rev !=0 ) + goto out_e_inval; + num_sub_bands =IWL_NUM_SUB_BANDS_V1 ;IWL_DEBUG_RADIO (fwrt,"Reading PPAG table v1 (tbl_rev=0)\n" ); goto read_table;
@@ -855,10 +841,8 @@ int iwl_acpi_get_ppag_table(struct iwl_fw_runtime *fwrt) fwrt->ppag_ver = tbl_rev; flags = &wifi_pkg->package.elements[1 ]; -if (flags->type !=ACPI_TYPE_INTEGER ) { - ret = -EINVAL ; - goto out_free; - } +if (flags->type !=ACPI_TYPE_INTEGER ) + goto out_e_inval; fwrt->ppag_flags =iwl_bios_get_ppag_flags (flags->integer.value, fwrt->ppag_ver);
@@ -873,10 +857,8 @@ int iwl_acpi_get_ppag_table(struct iwl_fw_runtime *fwrt)union acpi_object *ent; ent = &wifi_pkg->package.elements[idx++]; -if (ent->type !=ACPI_TYPE_INTEGER ) { - ret = -EINVAL ; - goto out_free; - } +if (ent->type !=ACPI_TYPE_INTEGER ) + goto out_e_inval; fwrt->ppag_chains[i].subbands[j] = ent->integer.value; }
@@ -887,6 +869,10 @@ int iwl_acpi_get_ppag_table(struct iwl_fw_runtime *fwrt) out_free:kfree (data);return ret; + +out_e_inval: + ret = -EINVAL ; + goto out_free; } void iwl_acpi_get_phy_filters(struct iwl_fw_runtime *fwrt,
--
2.43.0