Skip to content

Commit 4b3805d

Browse files
ytcooderafaeljw
authored andcommitted
ACPI: tables: Correct and clean up the logic of acpi_parse_entries_array()
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 4ceacd0 ("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 99b0efd ("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 8726d4f ("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: Yuntao Wang <ytcoode@gmail.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 33cc938 commit 4b3805d

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

lib/fw_table.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ acpi_get_subtable_type(char *id)
8585
return ACPI_SUBTABLE_COMMON;
8686
}
8787

88-
static __init_or_acpilib bool has_handler(struct acpi_subtable_proc *proc)
89-
{
90-
return proc->handler || proc->handler_arg;
91-
}
92-
9388
static __init_or_acpilib int call_handler(struct acpi_subtable_proc *proc,
9489
union acpi_subtable_headers *hdr,
9590
unsigned long end)
@@ -133,7 +128,6 @@ acpi_parse_entries_array(char *id, unsigned long table_size,
133128
unsigned long table_end, subtable_len, entry_len;
134129
struct acpi_subtable_entry entry;
135130
int count = 0;
136-
int errs = 0;
137131
int i;
138132

139133
table_end = (unsigned long)table_header + table_header->length;
@@ -145,25 +139,19 @@ acpi_parse_entries_array(char *id, unsigned long table_size,
145139
((unsigned long)table_header + table_size);
146140
subtable_len = acpi_get_subtable_header_length(&entry);
147141

148-
while (((unsigned long)entry.hdr) + subtable_len < table_end) {
149-
if (max_entries && count >= max_entries)
150-
break;
151-
142+
while (((unsigned long)entry.hdr) + subtable_len < table_end) {
152143
for (i = 0; i < proc_num; i++) {
153144
if (acpi_get_entry_type(&entry) != proc[i].id)
154145
continue;
155-
if (!has_handler(&proc[i]) ||
156-
(!errs &&
157-
call_handler(&proc[i], entry.hdr, table_end))) {
158-
errs++;
159-
continue;
160-
}
146+
147+
if (!max_entries || count < max_entries)
148+
if (call_handler(&proc[i], entry.hdr, table_end))
149+
return -EINVAL;
161150

162151
proc[i].count++;
152+
count++;
163153
break;
164154
}
165-
if (i != proc_num)
166-
count++;
167155

168156
/*
169157
* If entry->length is 0, break from this loop to avoid
@@ -180,9 +168,9 @@ acpi_parse_entries_array(char *id, unsigned long table_size,
180168
}
181169

182170
if (max_entries && count > max_entries) {
183-
pr_warn("[%4.4s:0x%02x] found the maximum %i entries\n",
184-
id, proc->id, count);
171+
pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
172+
id, proc->id, count - max_entries, count);
185173
}
186174

187-
return errs ? -EINVAL : count;
175+
return count;
188176
}

0 commit comments

Comments
 (0)