Skip to content

Commit 3ed83da

Browse files
committed
iwlwifi: fix ACPI table revision checks
We can't check for the ACPI table revision validity in the same if where we check if the package was read correctly, because we return PTR_ERR(pkg) and if the table is not valid but the pointer is, we would return a valid pointer as an error. Fix that by moving the table checks to a separate if and return -EINVAL if it's not valid. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Luca Coelho <[email protected]>
1 parent 1fee35d commit 3ed83da

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

drivers/net/wireless/intel/iwlwifi/fw/acpi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ int iwl_acpi_get_mcc(struct device *dev, char *mcc)
162162

163163
wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_WRDD_WIFI_DATA_SIZE,
164164
&tbl_rev);
165-
if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
165+
if (IS_ERR(wifi_pkg)) {
166166
ret = PTR_ERR(wifi_pkg);
167167
goto out_free;
168168
}
169169

170-
if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
170+
if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
171+
tbl_rev != 0) {
171172
ret = -EINVAL;
172173
goto out_free;
173174
}
@@ -224,12 +225,13 @@ int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
224225

225226
wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_ECKV_WIFI_DATA_SIZE,
226227
&tbl_rev);
227-
if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
228+
if (IS_ERR(wifi_pkg)) {
228229
ret = PTR_ERR(wifi_pkg);
229230
goto out_free;
230231
}
231232

232-
if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
233+
if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
234+
tbl_rev != 0) {
233235
ret = -EINVAL;
234236
goto out_free;
235237
}

drivers/net/wireless/intel/iwlwifi/mvm/fw.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,13 @@ static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
694694

695695
wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
696696
ACPI_WRDS_WIFI_DATA_SIZE, &tbl_rev);
697-
if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
697+
if (IS_ERR(wifi_pkg)) {
698698
ret = PTR_ERR(wifi_pkg);
699699
goto out_free;
700700
}
701701

702-
if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
702+
if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
703+
tbl_rev != 0) {
703704
ret = -EINVAL;
704705
goto out_free;
705706
}
@@ -731,13 +732,14 @@ static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
731732

732733
wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
733734
ACPI_EWRD_WIFI_DATA_SIZE, &tbl_rev);
734-
if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
735+
if (IS_ERR(wifi_pkg)) {
735736
ret = PTR_ERR(wifi_pkg);
736737
goto out_free;
737738
}
738739

739740
if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
740-
(wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
741+
(wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) ||
742+
tbl_rev != 0) {
741743
ret = -EINVAL;
742744
goto out_free;
743745
}
@@ -791,11 +793,16 @@ static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
791793

792794
wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
793795
ACPI_WGDS_WIFI_DATA_SIZE, &tbl_rev);
794-
if (IS_ERR(wifi_pkg) || tbl_rev > 1) {
796+
if (IS_ERR(wifi_pkg)) {
795797
ret = PTR_ERR(wifi_pkg);
796798
goto out_free;
797799
}
798800

801+
if (tbl_rev != 0) {
802+
ret = -EINVAL;
803+
goto out_free;
804+
}
805+
799806
mvm->geo_rev = tbl_rev;
800807
for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
801808
for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
@@ -1020,11 +1027,16 @@ static int iwl_mvm_get_ppag_table(struct iwl_mvm *mvm)
10201027
wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
10211028
ACPI_PPAG_WIFI_DATA_SIZE, &tbl_rev);
10221029

1023-
if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
1030+
if (IS_ERR(wifi_pkg)) {
10241031
ret = PTR_ERR(wifi_pkg);
10251032
goto out_free;
10261033
}
10271034

1035+
if (tbl_rev != 0) {
1036+
ret = -EINVAL;
1037+
goto out_free;
1038+
}
1039+
10281040
enabled = &wifi_pkg->package.elements[1];
10291041
if (enabled->type != ACPI_TYPE_INTEGER ||
10301042
(enabled->integer.value != 0 && enabled->integer.value != 1)) {

0 commit comments

Comments
 (0)