• Yuntao Wang's avatar
    ACPI: tables: Correct and clean up the logic of acpi_parse_entries_array() · 4b3805da
    Yuntao Wang authored
    The original intention of acpi_parse_entries_array() is to return the
    number of all matching entries on success. This number may be greater than
    the value of the max_entries parameter. When this happens, the function
    will output a warning message, indicating that `count - max_entries`
    matching entries remain unprocessed and have been ignored.
    
    However, commit 4ceacd02 ("ACPI / table: Always count matched and
    successfully parsed entries") changed this logic to return the number of
    entries successfully processed by the handler. In this case, when the
    max_entries parameter is not zero, the number of entries successfully
    processed can never be greater than the value of max_entries. In other
    words, the expression `count > max_entries` will always evaluate to false.
    This means that the logic in the final if statement will never be executed.
    
    Commit 99b0efd7 ("ACPI / tables: do not report the number of entries
    ignored by acpi_parse_entries()") mentioned this issue, but it tried to fix
    it by removing part of the warning message. This is meaningless because the
    pr_warn statement will never be executed in the first place.
    
    Commit 8726d4f4 ("ACPI / tables: fix acpi_parse_entries_array() so it
    traverses all subtables") introduced an errs variable, which is intended to
    make acpi_parse_entries_array() always traverse all of the subtables,
    calling as many of the callbacks as possible. However, it seems that the
    commit does not achieve this goal. For example, when a handler returns an
    error, none of the handlers will be called again in the subsequent
    iterations. This result appears to be no different from before the change.
    
    This patch corrects and cleans up the logic of acpi_parse_entries_array(),
    making it return the number of all matching entries, rather than the number
    of entries successfully processed by handlers. Additionally, if an error
    occurs when executing a handler, the function will return -EINVAL immediately.
    
    This patch should not affect existing users of acpi_parse_entries_array().
    Signed-off-by: default avatarYuntao Wang <ytcoode@gmail.com>
    Reviewed-by: default avatarDave Jiang <dave.jiang@intel.com>
    Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    4b3805da
fw_table.c 4.71 KB