Merge tag 'acpi-5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[sfrench/cifs-2.6.git] / drivers / firmware / efi / cper.c
index a7902fccdcfa4c5f39e42d6a4561d46a5a2a017b..8fa977c7861f961c32af4dfa3b949e9c5f1460ec 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * UEFI Common Platform Error Record (CPER) support
  *
@@ -9,19 +10,6 @@
  *
  * For more information about CPER, please refer to Appendix N of UEFI
  * Specification version 2.4.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include <linux/kernel.h>
@@ -546,19 +534,24 @@ EXPORT_SYMBOL_GPL(cper_estatus_check_header);
 int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
 {
        struct acpi_hest_generic_data *gdata;
-       unsigned int data_len, gedata_len;
+       unsigned int data_len, record_size;
        int rc;
 
        rc = cper_estatus_check_header(estatus);
        if (rc)
                return rc;
+
        data_len = estatus->data_length;
 
        apei_estatus_for_each_section(estatus, gdata) {
-               gedata_len = acpi_hest_get_error_length(gdata);
-               if (gedata_len > data_len - acpi_hest_get_size(gdata))
+               if (sizeof(struct acpi_hest_generic_data) > data_len)
                        return -EINVAL;
-               data_len -= acpi_hest_get_record_size(gdata);
+
+               record_size = acpi_hest_get_record_size(gdata);
+               if (record_size > data_len)
+                       return -EINVAL;
+
+               data_len -= record_size;
        }
        if (data_len)
                return -EINVAL;