From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Zhang Rui <rui.zhang@intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>
Subject: [PATCH v1 2/2] ACPI: utils: Add acpi_path_free and adjust acpi_handle_path()
Date: Fri, 04 Dec 2026 17:20:13 +0100 [thread overview]
Message-ID: <3455879.44csPzL39Z@rafael.j.wysocki> (raw)
In-Reply-To: <2290486.irdbgypaU6@rafael.j.wysocki>
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Introduce acpi_path_free for auto-freeing ACPI object paths returned
by acpi_handle_path() and adjust the latter to return a const char
pointer because that's what all of its users assign it to. While at
it, clean up the acpi_handle_path() function body a bit.
Use acpi_path_free in acpi_handle_printk() and __acpi_handle_debug()
that already call acpi_handle_path() and make acpi_object_path()
call acpi_handle_path() and use acpi_path_free to reduce code
duplication.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/device_sysfs.c | 10 +++-------
drivers/acpi/utils.c | 19 +++++++++----------
include/linux/acpi.h | 5 ++++-
3 files changed, 16 insertions(+), 18 deletions(-)
--- a/drivers/acpi/device_sysfs.c
+++ b/drivers/acpi/device_sysfs.c
@@ -20,15 +20,11 @@
static ssize_t acpi_object_path(acpi_handle handle, char *buf)
{
- struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
- int result;
-
- if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &path)))
+ const char *path __free(acpi_path_free) = acpi_handle_path(handle);
+ if (!path)
return -ENODATA;
- result = sysfs_emit(buf, "%s\n", (char *)path.pointer);
- kfree(path.pointer);
- return result;
+ return sysfs_emit(buf, "%s\n", path);
}
struct acpi_data_node_attr {
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -599,18 +599,21 @@ EXPORT_SYMBOL(acpi_evaluate_ost);
* acpi_handle_path: Return the object path of handle
* @handle: ACPI device handle
*
- * Caller must free the returned buffer
+ * Caller must free the returned buffer or use acpi_path_free.
*/
-char *acpi_handle_path(acpi_handle handle)
+const char *acpi_handle_path(acpi_handle handle)
{
struct acpi_buffer buffer = {
.length = ACPI_ALLOCATE_BUFFER,
.pointer = NULL
};
- if (in_interrupt() ||
- acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK)
+ if (in_interrupt())
return NULL;
+
+ if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
+ return NULL;
+
return buffer.pointer;
}
@@ -628,19 +631,17 @@ char *acpi_handle_path(acpi_handle handl
void
acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
{
+ const char *path __free(acpi_path_free) = acpi_handle_path(handle);
struct va_format vaf;
va_list args;
- const char *path;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
- path = acpi_handle_path(handle);
printk("%sACPI: %s: %pV", level, path ? path : "<n/a>", &vaf);
va_end(args);
- kfree(path);
}
EXPORT_SYMBOL(acpi_handle_printk);
@@ -660,19 +661,17 @@ void
__acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle,
const char *fmt, ...)
{
+ const char *path __free(acpi_path_free) = acpi_handle_path(handle);
struct va_format vaf;
va_list args;
- const char *path;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
- path = acpi_handle_path(handle);
__dynamic_pr_debug(descriptor, "ACPI: %s: %pV", path ? path : "<n/a>", &vaf);
va_end(args);
- kfree(path);
}
EXPORT_SYMBOL(__acpi_handle_debug);
#endif
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1280,7 +1280,10 @@ static inline void acpi_ec_set_gpe_wake_
#endif
#ifdef CONFIG_ACPI
-char *acpi_handle_path(acpi_handle handle);
+DEFINE_FREE(acpi_path_free, const char *, if (_T) ACPI_FREE((void *)_T));
+
+const char *acpi_handle_path(acpi_handle handle);
+
__printf(3, 4)
void acpi_handle_printk(const char *level, acpi_handle handle,
const char *fmt, ...);
next prev parent reply other threads:[~2026-12-04 16:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:17 [PATCH v1 0/2] ACPI: sysfs/utils: Fix and simplification related to object paths Rafael J. Wysocki
2026-12-04 16:18 ` [PATCH v1 1/2] ACPI: sysfs: Fix acpi_object_path() return value Rafael J. Wysocki
2026-12-04 17:37 ` Andy Shevchenko
2026-12-04 16:20 ` Rafael J. Wysocki [this message]
2026-12-04 17:40 ` [PATCH v1 2/2] ACPI: utils: Add acpi_path_free and adjust acpi_handle_path() Andy Shevchenko
2026-12-04 18:03 ` Rafael J. Wysocki (Intel)
2026-12-04 17:41 ` [PATCH v1 0/2] ACPI: sysfs/utils: Fix and simplification related to object paths Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3455879.44csPzL39Z@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=rui.zhang@intel.com \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox