From patchwork Fri Feb 16 09:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13559772 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mout.web.de (mout.web.de [212.227.15.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26429286AD; Fri, 16 Feb 2024 09:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708077384; cv=none; b=l4mcqAfyIaeOgBeYvvaecSEmwfrk/MrwOBw14IjFetPpYpwvPv+7aUlaO8khPp2/NKV1fElmTaG9dUXKYd/OLqJur8f38ZGiJ3Jxq/I9+RMN7mcg8ohIVYNSDXk1BA16CocJF+dHU4FyQHeCMycPGD7lMaSlbo3lau/rjcKyySY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708077384; c=relaxed/simple; bh=j4WYdlH2C0SjARdDRBqYCOTeUj3v1ffV3fGDsF0zbRM=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=XNapF43S3x151vAJrJFk25i8YCAhPgE8kMVTLICXWdE3oQCFh8aza4kf+byPhbtO0lxUbKsZmKHRDZcOVqEQNSD5qRlQBML1OstcAguoaBSoaz3mhbJaKnBbqjoGYFNC82cQ06wXOwH5IqnVQD1hPfKltm4eMataWxcAIVPcjX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b=iz7Ye9Sp; arc=none smtp.client-ip=212.227.15.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="iz7Ye9Sp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1708077374; x=1708682174; i=markus.elfring@web.de; bh=j4WYdlH2C0SjARdDRBqYCOTeUj3v1ffV3fGDsF0zbRM=; h=X-UI-Sender-Class:Date:From:Subject:To:Cc; b=iz7Ye9SpWpUmC8Hr0DfRZV7pfVRPEplG1eviG2cAguU9yzhnKMfeMJqYas+fgrJc YIwxsqmLKUnyLLJWLKTroau9eidgH2X53s593F1Uu8Yzp9W9jY6dqCiAuap33WCCl hCIRHZIbJY+mOf+n1ZRbYRGMCLp5+gfDO8cmN7rdWknneqmjQxxowx2WU6U4eby6K conea6e0xQRH7mI2wfx2q0lc8atcryD1tIbRprmqcKdnM0aae4BtK6L3Z1MXI7UXF YV/BHu3pC2xu2PS8pTYjNuhi5MbcEkv3DbIqNr5EzAJUcpNQbK+eku2EV5BjUDZ0c jcj1HklLGP1lWe9h8A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.80.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MeDMR-1qzvHw2FUN-00bHl6; Fri, 16 Feb 2024 10:50:43 +0100 Message-ID: <4b50017b-d3f6-45c8-b4a0-6943c7a7e54e@web.de> Date: Fri, 16 Feb 2024 10:50:27 +0100 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-GB From: Markus Elfring Subject: [PATCH] iwlwifi: Use common error handling code in five functions To: linux-wireless@vger.kernel.org, kernel-janitors@vger.kernel.org, Alon Giladi , Anjaneyulu , Dan Carpenter , Greg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PP/pm EdkYPRkC1XhzuEGtctlLSr7GlCdl40iGif3g8QtJkQcW8iFYjn5UgxeOnDj2VkKIEX6Wa02Ba AyZJGJRmVswx434xE8toyJyzvNm/f40SP1B2wsvsLFIsA= From: Markus Elfring 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 --- drivers/net/wireless/intel/iwlwifi/fw/acpi.c | 130 +++++++++---------- 1 file changed, 58 insertions(+), 72 deletions(-) -- 2.43.0 diff --git a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c index 4caf2e25a297..0d7a2f2eab07 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c @@ -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,