@@ -329,21 +329,18 @@ const char *acpi_get_subsystem_id(acpi_handle handle)
329329}
330330EXPORT_SYMBOL_GPL (acpi_get_subsystem_id );
331331
332- acpi_status
333- acpi_evaluate_reference (acpi_handle handle ,
334- acpi_string pathname ,
335- struct acpi_object_list * arguments ,
336- struct acpi_handle_list * list )
332+ bool acpi_evaluate_reference (acpi_handle handle , acpi_string pathname ,
333+ struct acpi_object_list * arguments ,
334+ struct acpi_handle_list * list )
337335{
338- acpi_status status = AE_OK ;
339- union acpi_object * package = NULL ;
340- union acpi_object * element = NULL ;
341336 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER , NULL };
342- u32 i = 0 ;
343-
337+ union acpi_object * package ;
338+ acpi_status status ;
339+ bool ret = false;
340+ u32 i ;
344341
345342 if (!list )
346- return AE_BAD_PARAMETER ;
343+ return false ;
347344
348345 /* Evaluate object. */
349346
@@ -353,62 +350,47 @@ acpi_evaluate_reference(acpi_handle handle,
353350
354351 package = buffer .pointer ;
355352
356- if ((buffer .length == 0 ) || !package ) {
357- status = AE_BAD_DATA ;
358- acpi_util_eval_error (handle , pathname , status );
359- goto end ;
360- }
361- if (package -> type != ACPI_TYPE_PACKAGE ) {
362- status = AE_BAD_DATA ;
363- acpi_util_eval_error (handle , pathname , status );
364- goto end ;
365- }
366- if (!package -> package .count ) {
367- status = AE_BAD_DATA ;
368- acpi_util_eval_error (handle , pathname , status );
369- goto end ;
370- }
353+ if (buffer .length == 0 || !package ||
354+ package -> type != ACPI_TYPE_PACKAGE || !package -> package .count )
355+ goto err ;
371356
372- list -> handles = kcalloc (package -> package .count , sizeof (* list -> handles ), GFP_KERNEL );
373- if (!list -> handles ) {
374- kfree (package );
375- return AE_NO_MEMORY ;
376- }
377357 list -> count = package -> package .count ;
358+ list -> handles = kcalloc (list -> count , sizeof (* list -> handles ), GFP_KERNEL );
359+ if (!list -> handles )
360+ goto err_clear ;
378361
379362 /* Extract package data. */
380363
381364 for (i = 0 ; i < list -> count ; i ++ ) {
365+ union acpi_object * element = & (package -> package .elements [i ]);
382366
383- element = & (package -> package .elements [i ]);
367+ if (element -> type != ACPI_TYPE_LOCAL_REFERENCE ||
368+ !element -> reference .handle )
369+ goto err_free ;
384370
385- if (element -> type != ACPI_TYPE_LOCAL_REFERENCE ) {
386- status = AE_BAD_DATA ;
387- acpi_util_eval_error (handle , pathname , status );
388- break ;
389- }
390-
391- if (!element -> reference .handle ) {
392- status = AE_NULL_ENTRY ;
393- acpi_util_eval_error (handle , pathname , status );
394- break ;
395- }
396371 /* Get the acpi_handle. */
397372
398373 list -> handles [i ] = element -> reference .handle ;
399374 acpi_handle_debug (list -> handles [i ], "Found in reference list\n" );
400375 }
401376
402- if (ACPI_FAILURE (status )) {
403- list -> count = 0 ;
404- kfree (list -> handles );
405- list -> handles = NULL ;
406- }
377+ ret = true;
407378
408379end :
409380 kfree (buffer .pointer );
410381
411- return status ;
382+ return ret ;
383+
384+ err_free :
385+ kfree (list -> handles );
386+ list -> handles = NULL ;
387+
388+ err_clear :
389+ list -> count = 0 ;
390+
391+ err :
392+ acpi_util_eval_error (handle , pathname , status );
393+ goto end ;
412394}
413395
414396EXPORT_SYMBOL (acpi_evaluate_reference );
@@ -426,7 +408,7 @@ bool acpi_handle_list_equal(struct acpi_handle_list *list1,
426408{
427409 return list1 -> count == list2 -> count &&
428410 !memcmp (list1 -> handles , list2 -> handles ,
429- list1 -> count * sizeof (acpi_handle ));
411+ list1 -> count * sizeof (* list1 -> handles ));
430412}
431413EXPORT_SYMBOL_GPL (acpi_handle_list_equal );
432414
@@ -468,6 +450,40 @@ void acpi_handle_list_free(struct acpi_handle_list *list)
468450}
469451EXPORT_SYMBOL_GPL (acpi_handle_list_free );
470452
453+ /**
454+ * acpi_device_dep - Check ACPI device dependency
455+ * @target: ACPI handle of the target ACPI device.
456+ * @match: ACPI handle to look up in the target's _DEP list.
457+ *
458+ * Return true if @match is present in the list returned by _DEP for
459+ * @target or false otherwise.
460+ */
461+ bool acpi_device_dep (acpi_handle target , acpi_handle match )
462+ {
463+ struct acpi_handle_list dep_devices ;
464+ bool ret = false;
465+ int i ;
466+
467+ if (!acpi_has_method (target , "_DEP" ))
468+ return false;
469+
470+ if (!acpi_evaluate_reference (target , "_DEP" , NULL , & dep_devices )) {
471+ acpi_handle_debug (target , "Failed to evaluate _DEP.\n" );
472+ return false;
473+ }
474+
475+ for (i = 0 ; i < dep_devices .count ; i ++ ) {
476+ if (dep_devices .handles [i ] == match ) {
477+ ret = true;
478+ break ;
479+ }
480+ }
481+
482+ acpi_handle_list_free (& dep_devices );
483+ return ret ;
484+ }
485+ EXPORT_SYMBOL_GPL (acpi_device_dep );
486+
471487acpi_status
472488acpi_get_physical_device_location (acpi_handle handle , struct acpi_pld_info * * pld )
473489{
@@ -824,54 +840,6 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
824840}
825841EXPORT_SYMBOL (acpi_check_dsm );
826842
827- /**
828- * acpi_dev_uid_match - Match device by supplied UID
829- * @adev: ACPI device to match.
830- * @uid2: Unique ID of the device.
831- *
832- * Matches UID in @adev with given @uid2.
833- *
834- * Returns:
835- * - %true if matches.
836- * - %false otherwise.
837- */
838- bool acpi_dev_uid_match (struct acpi_device * adev , const char * uid2 )
839- {
840- const char * uid1 = acpi_device_uid (adev );
841-
842- return uid1 && uid2 && !strcmp (uid1 , uid2 );
843- }
844- EXPORT_SYMBOL_GPL (acpi_dev_uid_match );
845-
846- /**
847- * acpi_dev_hid_uid_match - Match device by supplied HID and UID
848- * @adev: ACPI device to match.
849- * @hid2: Hardware ID of the device.
850- * @uid2: Unique ID of the device, pass NULL to not check _UID.
851- *
852- * Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2
853- * will be treated as a match. If user wants to validate @uid2, it should be
854- * done before calling this function.
855- *
856- * Returns:
857- * - %true if matches or @uid2 is NULL.
858- * - %false otherwise.
859- */
860- bool acpi_dev_hid_uid_match (struct acpi_device * adev ,
861- const char * hid2 , const char * uid2 )
862- {
863- const char * hid1 = acpi_device_hid (adev );
864-
865- if (strcmp (hid1 , hid2 ))
866- return false;
867-
868- if (!uid2 )
869- return true;
870-
871- return acpi_dev_uid_match (adev , uid2 );
872- }
873- EXPORT_SYMBOL (acpi_dev_hid_uid_match );
874-
875843/**
876844 * acpi_dev_uid_to_integer - treat ACPI device _UID as integer
877845 * @adev: ACPI device to get _UID from
0 commit comments