ACPI / bus: Do not traverse through non-existed device table
PATCH v3 2/5 ACPI / bus: Do not traverse through non-existed device table
Quoted 22 lines · Rafael J. Wysocki
Quoted 16 lines · Andy Shevchenko
When
__acpi_match_device()is called it would be possible to have ACPI ID table a MULL pointer. To avoid potential dereference, check for this before traverse.While here, remove redundant 'else'.
(quoted diff) +3
-0+ if (ids) { + for (id = ids; id->id[0] || id->cls; id++) { + if (id->id[0] && !strcmp((char *)id-Quoted 1 line
id,
hwid->id))(quoted diff) +2
-0+ return id; + if (id->cls &&
__acpi_match_device_cls(id, hwid))Review
Quoted 2 lines
(quoted diff) +2
-0+ return id; + }
Quoted 2 lines
The return value below should be updated in *this* patch, because this is what allows ids to be NULL in the first place.
OK, so I'll fold it into patch 1 then.
Quoted 7 lines
And as far as I'm concerned you can do:
if (!strcmp(ACPI_DT_NAMESPACE_HID,
hwid->id)
return (const structacpi_device_id
*)acpi_of_match_device(device,of_ids);and update the comment accordingly.
But it's still a trick.
Okay, what comes to my mind (yes, not so simple, but cleaner I suppose) is to define
struct acpi_of_device_id {
struct acpi_device_id *acpi_id;
struct of_device_id *of_id;
};
Add a new parameter to acpi_of_match_device(..., struct acpi_of_device_id *id).
Update __acpi_match_device() in the similar way.
Update callers.
It looks to me much more cleaner.