diff mbox series

[v2,1/2] ACPI: utils: Add api to read _SUB from ACPI

Message ID 20220627141148.804319-2-sbinding@opensource.cirrus.com (mailing list archive)
State Superseded, archived
Headers show
Series Read _SUB from ACPI to be able to identify firmware | expand

Commit Message

Stefan Binding June 27, 2022, 2:11 p.m. UTC
Add a wrapper function to read the _SUB string from ACPI.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
 drivers/acpi/utils.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h |  6 ++++++
 2 files changed, 44 insertions(+)

Comments

kernel test robot June 27, 2022, 3:33 p.m. UTC | #1
Hi Stefan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on broonie-sound/for-next linus/master v5.19-rc4 next-20220627]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Stefan-Binding/Read-_SUB-from-ACPI-to-be-able-to-identify-firmware/20220627-221508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: um-x86_64_defconfig (https://download.01.org/0day-ci/archive/20220627/202206272354.ESTdiIXg-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/93ba13d4b3636b5cf2ff4d9185aa73f059cc7b2a
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Stefan-Binding/Read-_SUB-from-ACPI-to-be-able-to-identify-firmware/20220627-221508
        git checkout 93ba13d4b3636b5cf2ff4d9185aa73f059cc7b2a
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=um SUBARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from init/main.c:30:
>> include/linux/acpi.h:1028:1: error: expected identifier or '(' before '{' token
    1028 | {
         | ^
   init/main.c:769:20: warning: no previous prototype for 'arch_post_acpi_subsys_init' [-Wmissing-prototypes]
     769 | void __init __weak arch_post_acpi_subsys_init(void) { }
         |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
   init/main.c:781:20: warning: no previous prototype for 'mem_encrypt_init' [-Wmissing-prototypes]
     781 | void __init __weak mem_encrypt_init(void) { }
         |                    ^~~~~~~~~~~~~~~~
   init/main.c:783:20: warning: no previous prototype for 'poking_init' [-Wmissing-prototypes]
     783 | void __init __weak poking_init(void) { }
         |                    ^~~~~~~~~~~
   In file included from init/main.c:30:
   include/linux/acpi.h:1027:27: warning: 'acpi_get_subsystem_id' declared 'static' but never defined [-Wunused-function]
    1027 | static inline const char *acpi_get_subsystem_id(acpi_handle handle);
         |                           ^~~~~~~~~~~~~~~~~~~~~
--
   In file included from kernel/sysctl.c:55:
>> include/linux/acpi.h:1028:1: error: expected identifier or '(' before '{' token
    1028 | {
         | ^
   include/linux/acpi.h:1027:27: warning: 'acpi_get_subsystem_id' declared 'static' but never defined [-Wunused-function]
    1027 | static inline const char *acpi_get_subsystem_id(acpi_handle handle);
         |                           ^~~~~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/i2c.h:13,
                    from drivers/input/mouse/synaptics.c:30:
>> include/linux/acpi.h:1028:1: error: expected identifier or '(' before '{' token
    1028 | {
         | ^
   include/linux/acpi.h:1027:27: warning: 'acpi_get_subsystem_id' declared 'static' but never defined [-Wunused-function]
    1027 | static inline const char *acpi_get_subsystem_id(acpi_handle handle);
         |                           ^~~~~~~~~~~~~~~~~~~~~
   drivers/input/mouse/synaptics.c:164:27: warning: 'smbus_pnp_ids' defined but not used [-Wunused-const-variable=]
     164 | static const char * const smbus_pnp_ids[] = {
         |                           ^~~~~~~~~~~~~


vim +1028 include/linux/acpi.h

  1026	
  1027	static inline const char *acpi_get_subsystem_id(acpi_handle handle);
> 1028	{
  1029		return ERR_PTR(-ENODEV);
  1030	}
  1031
diff mbox series

Patch

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 3a9773a09e19..4ef9ee4ad0d8 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -291,6 +291,44 @@  int acpi_get_local_address(acpi_handle handle, u32 *addr)
 }
 EXPORT_SYMBOL(acpi_get_local_address);
 
+#define ACPI_MAX_SUB_BUF_SIZE	9
+
+const char *acpi_get_subsystem_id(acpi_handle handle)
+{
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	union acpi_object *obj;
+	acpi_status status;
+	const char *sub;
+
+	status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer);
+	if (ACPI_FAILURE(status)) {
+		acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status);
+		return ERR_PTR(-ENODATA);
+	}
+
+	obj = buffer.pointer;
+	if (obj->type == ACPI_TYPE_STRING) {
+		if (strlen(obj->string.pointer) < ACPI_MAX_SUB_BUF_SIZE &&
+		    strlen(obj->string.pointer) > 0) {
+			sub = kstrdup(obj->string.pointer, GFP_KERNEL);
+			if (!sub)
+				sub = ERR_PTR(-ENOMEM);
+		} else {
+			acpi_handle_err(handle, "ACPI _SUB Length %d is Invalid\n",
+					strlen(obj->string.pointer));
+			sub = ERR_PTR(-EINVAL);
+		}
+	} else {
+		acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n");
+		sub = ERR_PTR(-EINVAL);
+	}
+
+	acpi_os_free(buffer.pointer);
+
+	return sub;
+}
+EXPORT_SYMBOL_GPL(acpi_get_subsystem_id);
+
 acpi_status
 acpi_evaluate_reference(acpi_handle handle,
 			acpi_string pathname,
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 4f82a5bc6d98..1c13fc077f42 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -762,6 +762,7 @@  static inline u64 acpi_arch_get_root_pointer(void)
 #endif
 
 int acpi_get_local_address(acpi_handle handle, u32 *addr);
+const char *acpi_get_subsystem_id(acpi_handle handle);
 
 #else	/* !CONFIG_ACPI */
 
@@ -1023,6 +1024,11 @@  static inline int acpi_get_local_address(acpi_handle handle, u32 *addr)
 	return -ENODEV;
 }
 
+static inline const char *acpi_get_subsystem_id(acpi_handle handle);
+{
+	return ERR_PTR(-ENODEV);
+}
+
 static inline int acpi_register_wakeup_handler(int wake_irq,
 	bool (*wakeup)(void *context), void *context)
 {