ACPICA: Utilities: Fix memory leak in acpi_ut_copy_iobject_to_iobject

Adds return status check on copy routines to delete the allocated destination
object if either copy fails. Reported by Colin Ian King on bugs.acpica.org,
Bug 1087.
The last applicable commit:
 Commit: 3371c19c294a4cb3649aa4e84606be8a1d999e61
 Subject: ACPICA: Remove ACPI_GET_OBJECT_TYPE macro

Link: https://bugs.acpica.org/show_bug.cgi?id=1087
Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: acpidump: Add support for ACPI 1.0 GUID in Linux

For older EFI platforms, searches for the RSDP using ACPI 1.0 GUID if the
2.0 GUID search fails.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Utilities: Fix an issue with non-native ACPI_IS_PRINT()

An error was found in the ACPICA provided non-native ACPI_IS_PRINT() causing the
following difference with the native isprint() implementation:
  The GNU libc isprint('\n') test result:
   isprint(0x20) is FALSE
  The Linux kernel isprint('\n') test result:
   ACPI: isprint(0x20) is FALSE
  The _acpi_ctype isprint('\n') test result:
   isprint(0x20) is TRUE

The ACPI_IS_PRINT() macro generated for _acpi_ctype is wrong. It should use
_ACPI_XS instead of _ACPI_SP.  _ACPI_XS is white space only. Other space
characters should be non printable.

This patch fixes this issue. For OSPMs that are using native standard
isprint() implementations, this patch is a no-op. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Utilities: Add support to read table from files

After the new table reading utility functions are well tested, acpidump can
also switch to use the generic acpi_ut_read_table_xxx() APIs. Currently
this patch is no-op as acpidump does not link to the new APIs.

This patch is only useful for ACPICA applications, most of which are not
shipped in the Linux kernel.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Utilities: Validate full RSDP header

Implement proper RSDP validation in acpi_ut_read_table(). Prevents a segmentation
fault that can occur if a user passes the wrong file to iasl.

This patch is only useful for iasl, which is not shipped in the Linux
kernel.

After the new table reading utility functions are well tested, acpidump can
also switch to use the generic acpi_ut_read_table_xxx() APIs. Currently
this patch is no-op as acpidump does not link to the new APIs.

Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Namespace: Properly null terminate objects detached from a namespace node

Fixes a bug exposed by an ACPICA unit test around the
acpi_attach_data()/acpi_detach_data() APIs where the failure to null
terminate a detached object led to the creation of a circular linked list
(and infinite looping) when the object is reattached.

Reported in acpica bugzilla #1063

Link: https://bugs.acpica.org/show_bug.cgi?id=1063
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Cc: 3.15+ <stable@vger.kernel.org> # 3.15+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: OSL: Update environments to improve portability

This patch contains some environment updates that will be used by acpidump
because:
 1. The follow-up commits will release osunixxf.c to the Linux kernel for
    acpidump to link, and
 2. Such environment settings will be used to avoid linkage issues.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Utilities: Cleanup DEFINE_ACPI_GLOBALS by moving acpi_ut_init_global() from utglobal.c to utinit.c

The utglobal.c is used to define and initialize global variables.  It makes
sense if just adding utglobal.o to applications that are using such
variables. But acpi_ut_init_globals() is preventing us from doing so as
this initialization function references other components' initializations
code, which leads to the requirement that many files should also get linked
if one wants to link utglobal.o.

It is possible to just move acpi_ut_init_global() to utinit.c for
applications that require this function to link.

By linking utglobal.o, we can stop defining DEFINE_ACPI_GLOBALS for
applications (currently only acpidump is affected). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: OSL: Clean up acpi_os_printf()/acpi_os_vprintf() stubs

This patch is mainly for acpidump where there are redundant
acpi_os_printf()/acpi_os_vprintf() stubs implemented. This patch cleans up such
specific implementation by linking acpidump to osunixxf.c/oswinxf.c.

To make acpi_os_printf() exported by osunixxf.c/oswinxf.c to behave as the
old acpidump specific ones, applications need to:
 1. Initialize acpi_gbl_db_output_flags to ACPI_DB_CONSOLE_OUTPUT.
    This is automatically done by ACPI_INIT_GLOBAL(), applications need to
    link utglobal.o to utilize this mechanism.
 2. Initialize acpi_gbl_output_file to stdout.
    For GCC, assigning stdout to acpi_gbl_output_file using ACPI_INIT_GLOBAL()
    is not possible as stdout is not a constant in GCC environment. As an
    alternative solution, stdout assignment is put into acpi_os_initialize().
    Thus acpi_os_initialize() need to be invoked very early by the
    applications to initialize the default output of acpi_os_printf().

This patch also releases osunixxf.c to the Linux kernel. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: OSL: Add portable file IO to improve portability

This patch adds portable file IO to generic OSL to improve the portability
of the applications.

A portable application may use different file IO interfaces than the
standard C library ones. This patch thus introduces an abstract file IO
layer into the generic OSL.

Note that this patch does not introduce users of such interfaces, further
patches should introduce users one by one carefully with build tests
performed. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Utilities: Add formatted printing APIs

This patch introduces formatted printing APIs to handle ACPICA specific
formatted print requirements. Currently only specific OSPMs will use this
customized printing support, Linux kernel doesn't use these APIs at this
time. It will be enabled for Linux kernel resident ACPICA after being well
tested. So currently this patch is a no-op.

The specific formatted printing APIs are useful to ACPICA as:
 1. Some portable applications do not link standard C library, so they
    cannot use standard formatted print APIs directly.
 2. Platform specific printing format may differ and thus not portable, for
    example, u64 is %ull for Linux kernel and is %uI64 for some MSVC
    versions.
 3. Platform specific printing format may conflict with ACPICA's usages
    while it is not possible for ACPICA developers to test their code for
    all platforms. For example, developers may generate %pRxxx while Linux
    kernel treats %pR as structured resource printing and decodes variable
    argument as a "struct resource" pointer.
This patch solves above issues by introducing the new APIs.

Note that users of such APIs are not introduced in this patch. Users of
acpi_os_file_vprintf()/acpi_ut_file_printf() need to invoke acpi_os_initialize(),
this should be taken care by the further patches where such users are
introduced. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Utilities: Introduce acpi_log_error() to improve portability

Invocations like fprintf(stderr) and perror() are not portable, this patch
introduces acpi_log_error() as a replacement, it is implemented using new
portable API - acpi_ut_file_vprintf().

Note that though acpi_os_initialize() need to be invoked prior than using
this new API, since no users are introduced in this patch, such invocations
are not added for applications that link utprint.c in this patch. Futher
patches that introduce users of acpi_log_error() should take care of this.

This patch is only useful for ACPICA applications, most of which are not
shipped in the Linux kernel.

Note that follow-up commits will update acpidump to use this new API to
improve portability. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Application: Enhance ACPI_USAGE_xxx/ACPI_OPTION with acpi_os_printf() to improve portability

This patch enhances ACPI_USAGE_xxx/ACPI_OPTION macros to use portable
acpi_os_printf() so that usage functions for applications no longer rely on
the printf() API.

To use acpi_os_printf() exported by osunixxf.c as a replacement of
printf(), applications need to initialize acpi_gbl_output_file to stdout
and initialize acpi_gbl_db_output_flags to ACPI_DB_CONSOLE_OUTPUT. The
latter is automatically done by ACPI_INIT_GLOBAL(), applications need to
link utglobal.o to utilize this mechanism. For GCC, assigning stdout to
acpi_gbl_output_file using ACPI_INIT_GLOBAL() is not possible as stdout is
not a constant in GCC environment. As an alternative solution, stdout
assignment has been put into acpi_os_initialize(). Thus
acpi_os_initialize() need to be invoked very early by the applications to
initialize the default output of acpi_os_printf() to keep behavior
consistency.

acpidump has already invoked acpi_os_initialize() in this way. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Common: Enhance cm_get_file_size() to improve portability

This patch uses abstract file IO and acpi_log_error() APIs to enhance
cm_get_file_size() so that applications that invoke this API could have
portability improved.

With actual references added to abstract file IO and acpi_log_error(), the
applications need to link oslibcfs.o, utdebug.o, utexcep.o, utmath.o,
utprint.o and utxferror.o.

It is also required to add acpi_os_initialize() invocations if an
application starts to use acpi_log_error().

acpidump has already invoked acpi_os_initialize() in this way.  Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: Common: Enhance acpi_getopt() to improve portability

This patch enhances acpi_getopt() by converting the standard C library
invocations into portable ACPI string APIs and acpi_log_error() to improve
portability. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: acpidump: Add memory/string OSL usage to improve portability

This patch adds code to use generic OSL for acpidump to improve the
portability of this tool. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: acpidump: Remove exit() from generic layer to improve portability

This patch removes exit() from generic acpidump code to improve the
portability of this tool. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: acpidump: Replace file IOs with new APIs to improve portability

The new APIs are enabled to offer a portable layer to access files:
 1. acpi_os_XXX_file_XXX: Wrapper of fopen/fclose/fread/fwrite
 2. acpi_os_printf: Wrapper of printf
 3. acpi_log_error: Wrapper of fprintf(stderr)

This patch deploys such mechanisms to acpidump to improve the portability
of this tool. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: acpidump: Reduce freopen() invocations to improve portability

This patch reduces the requirement of invoking freopen() in acpidump in order
to reduce the porting effort of acpidump.

This patch achieves this by turning all acpi_os_printf(stdout) into
acpi_ut_file_printf(gbl_output_file). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPICA: OSL: Update acpidump to reduce source code differences

This patch is a result of an ACPICA commit to enables acpidump for EFI. For
Linux kernel, this patch is a no-op. It is only required by the ACPICA
release process to reduce the source code differences between the Linux
kernel and the ACPICA upstream. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>