Skip to content

Commit e1acdeb

Browse files
committed
ACPI / scan: Simplify acpi_match_device()
Redefine acpi_companion_match() to return an ACPI device object pointer instead of a bool and use it to remove some redundant code from acpi_match_device(). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent 54fe9ce commit e1acdeb

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

drivers/acpi/scan.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
194194
*
195195
* Check if the given device has an ACPI companion and if that companion has
196196
* a valid list of PNP IDs, and if the device is the first (primary) physical
197-
* device associated with it.
197+
* device associated with it. Return the companion pointer if that's the case
198+
* or NULL otherwise.
198199
*
199200
* If multiple physical devices are attached to a single ACPI companion, we need
200201
* to be careful. The usage scenario for this kind of relationship is that all
@@ -208,31 +209,31 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
208209
* resources available from it but they will be matched normally using functions
209210
* provided by their bus types (and analogously for their modalias).
210211
*/
211-
static bool acpi_companion_match(const struct device *dev)
212+
static struct acpi_device *acpi_companion_match(const struct device *dev)
212213
{
213214
struct acpi_device *adev;
214-
bool ret;
215215

216216
adev = ACPI_COMPANION(dev);
217217
if (!adev)
218-
return false;
218+
return NULL;
219219

220220
if (list_empty(&adev->pnp.ids))
221-
return false;
221+
return NULL;
222222

223223
mutex_lock(&adev->physical_node_lock);
224224
if (list_empty(&adev->physical_node_list)) {
225-
ret = false;
225+
adev = NULL;
226226
} else {
227227
const struct acpi_device_physical_node *node;
228228

229229
node = list_first_entry(&adev->physical_node_list,
230230
struct acpi_device_physical_node, node);
231-
ret = node->dev == dev;
231+
if (node->dev != dev)
232+
adev = NULL;
232233
}
233234
mutex_unlock(&adev->physical_node_lock);
234235

235-
return ret;
236+
return adev;
236237
}
237238

238239
/*
@@ -904,7 +905,7 @@ static const struct acpi_device_id *__acpi_match_device(
904905
* If the device is not present, it is unnecessary to load device
905906
* driver for it.
906907
*/
907-
if (!device->status.present)
908+
if (!device || !device->status.present)
908909
return NULL;
909910

910911
for (id = ids; id->id[0]; id++)
@@ -929,16 +930,7 @@ static const struct acpi_device_id *__acpi_match_device(
929930
const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
930931
const struct device *dev)
931932
{
932-
struct acpi_device *adev;
933-
acpi_handle handle = ACPI_HANDLE(dev);
934-
935-
if (!ids || !handle || acpi_bus_get_device(handle, &adev))
936-
return NULL;
937-
938-
if (!acpi_companion_match(dev))
939-
return NULL;
940-
941-
return __acpi_match_device(adev, ids);
933+
return __acpi_match_device(acpi_companion_match(dev), ids);
942934
}
943935
EXPORT_SYMBOL_GPL(acpi_match_device);
944936

0 commit comments

Comments
 (0)