@@ -194,7 +194,8 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
194
194
*
195
195
* Check if the given device has an ACPI companion and if that companion has
196
196
* 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.
198
199
*
199
200
* If multiple physical devices are attached to a single ACPI companion, we need
200
201
* 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,
208
209
* resources available from it but they will be matched normally using functions
209
210
* provided by their bus types (and analogously for their modalias).
210
211
*/
211
- static bool acpi_companion_match (const struct device * dev )
212
+ static struct acpi_device * acpi_companion_match (const struct device * dev )
212
213
{
213
214
struct acpi_device * adev ;
214
- bool ret ;
215
215
216
216
adev = ACPI_COMPANION (dev );
217
217
if (!adev )
218
- return false ;
218
+ return NULL ;
219
219
220
220
if (list_empty (& adev -> pnp .ids ))
221
- return false ;
221
+ return NULL ;
222
222
223
223
mutex_lock (& adev -> physical_node_lock );
224
224
if (list_empty (& adev -> physical_node_list )) {
225
- ret = false ;
225
+ adev = NULL ;
226
226
} else {
227
227
const struct acpi_device_physical_node * node ;
228
228
229
229
node = list_first_entry (& adev -> physical_node_list ,
230
230
struct acpi_device_physical_node , node );
231
- ret = node -> dev == dev ;
231
+ if (node -> dev != dev )
232
+ adev = NULL ;
232
233
}
233
234
mutex_unlock (& adev -> physical_node_lock );
234
235
235
- return ret ;
236
+ return adev ;
236
237
}
237
238
238
239
/*
@@ -904,7 +905,7 @@ static const struct acpi_device_id *__acpi_match_device(
904
905
* If the device is not present, it is unnecessary to load device
905
906
* driver for it.
906
907
*/
907
- if (!device -> status .present )
908
+ if (!device || ! device -> status .present )
908
909
return NULL ;
909
910
910
911
for (id = ids ; id -> id [0 ]; id ++ )
@@ -929,16 +930,7 @@ static const struct acpi_device_id *__acpi_match_device(
929
930
const struct acpi_device_id * acpi_match_device (const struct acpi_device_id * ids ,
930
931
const struct device * dev )
931
932
{
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 );
942
934
}
943
935
EXPORT_SYMBOL_GPL (acpi_match_device );
944
936
0 commit comments