From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796401230; b=ZtrFYjJsoFncN5E3/jONG1d83wd0uCm5+s7NHVXkOq8TwsqqNSfOIqogpDAdu645e/gh ahQQy6DEkEN1zU6j1lHIx5Zv5M754IxJ6rebhCSmOcwHXPHETCDvi4Y6BVFiNZJ1mc2Vs 8fHExrx19vNYoCMOfXZw2HvcHnIrjhrGernVdy+i7nQAH7DCCNFZIErjkUv1pNpeSvQdW x1zMrV1fvF+dvUURPzIxbE6Xd3uSyt5Dr7HvszNTQWh06O0y1KK+Z5NYf+VN15WsbLn+N guqfGtYsLRPiLwv01Gtsx3dRILr/5sfLvrpmvktbwLD8ktQ5tev5D99aW7Oefl3RKYg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796401230; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: Organization:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type; bh=vaq3lwockiPc4hTrSnzQqfLUtVKE9mGmlOoBHJDV4OE=; b=ngiMcjSt0Q1CZQVzizvjOCvOA54h/PgSBlZGYYkIxWeR94PDf70RxM/INJOczjrqFYAe ZvT/IHvaQAX6YefTXAqcPt+dU63yzw3B39Xwjet4C6G6d2zpAOtl3PUObvfMYMVDu0gB5 5lLiNiC9VfErfg95J4N1vLAOZztKsKGgWSCw3TYeLXNfh1nLF8PY3DMZlbyWHn9+dde73 pR8pzE2/wPFRZErz0QtWo6Yke/VgOO1PcCuAovE9Z2ZeDFlCAnJ74IcWU/7UIrJHfVYKY rjzDFCTKEl84hEqwnaosZrYeljDBVJTB0FXDRw8TpgSUs4fbsmxbqkhn3L/71VUcs1w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="TO2gwt/Z"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A609606A322 for ; Fri, 4 Dec 2026 16:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TO2gwt/Z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 122C31F000C2; Fri, 4 Dec 2026 16:20:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796401229; bh=vaq3lwockiPc4hTrSnzQqfLUtVKE9mGmlOoBHJDV4OE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TO2gwt/ZgEEFIF1GzAIRbXik88KLx0UY2ipfrp8Jl80NO+b9a7QlE8UxNrR5M790s 1F1Zte20GpfkbqioE9Jhp00qFWH9EaDgBpsqMUVS4grpGUnIFa4rog1tEaASGqGYtz KFwiXdNY5u+/bnXD6tP+PLcM8RJChU6lr2ioTaeF4VbM6ia/JlVnGltJuZnaKIT2ch oBvTfuPoC/Ttb8uwMtrDuPV+jPrdfjL+508Pa81GhdgwAWyIuT6u5BFXLlF040X4yg 9LUQ2TkCgQq6518fb3gNUcXeJsw33BfBAdMOH569RDDGnFGJRK+aNHE/IK0hbrBFZW Q2vbTMIO0MxSQ== From: "Rafael J. Wysocki" To: Linux ACPI Cc: Andy Shevchenko , Zhang Rui , Sakari Ailus 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 Message-ID: <3455879.44csPzL39Z@rafael.j.wysocki> Organization: Linux Kernel Development - Intel In-Reply-To: <2290486.irdbgypaU6@rafael.j.wysocki> References: <2290486.irdbgypaU6@rafael.j.wysocki> X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" From: "Rafael J. Wysocki" 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 --- 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 : "", &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 : "", &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, ...);