From: Kaushlendra Kumar kaushlendra.kumar@intel.com
[ Upstream commit 149139ddcb99583fdec8d1eaf7dada41e5896101 ]
Since str_obj is allocated by ACPICA in acpi_evaluate_object_typed(), it should be free with ACPI_FREE() rather than with kfree(), so use the former instead of the latter for freeing it.
Signed-off-by: Kaushlendra Kumar kaushlendra.kumar@intel.com Link: https://patch.msgid.link/20250822061946.472594-1-kaushlendra.kumar@intel.com [ rjw: Subject and changelog rewrite ] Signed-off-by: Rafael J. Wysocki rafael.j.wysocki@intel.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
Based on my comprehensive investigation of this commit and the ACPICA memory management infrastructure, here is my analysis:
## Analysis Summary
**Backport Status: YES** (with low priority - code correctness/cleanup fix)
## Detailed Technical Analysis
### What This Commit Fixes
This commit changes one line in `drivers/acpi/device_sysfs.c:467`: - **Before**: `kfree(str_obj);` - **After**: `ACPI_FREE(str_obj);`
The `str_obj` is allocated by `acpi_evaluate_object_typed()` at line 447, which uses ACPICA's internal allocation mechanism.
### The Core Issue
In the Linux kernel's ACPICA implementation, there are two possible memory management paths:
1. **Normal Linux kernel builds** (ACPI_DBG_TRACK_ALLOCATIONS disabled): - `ACPI_FREE()` expands to `acpi_os_free()` - `acpi_os_free()` is implemented as `kfree()` (see `include/acpi/platform/aclinuxex.h:62-65`) - **Functionally equivalent**: `ACPI_FREE()` == `kfree()`
2. **ACPI debugging builds** (ACPI_DBG_TRACK_ALLOCATIONS enabled, only for acpi_exec utility): - `ACPI_FREE()` expands to `acpi_ut_free_and_track()` - This tracks allocations for memory leak detection - Using `kfree()` directly **breaks allocation tracking**
### Is This a Real Bug?
**In production Linux kernels: NO** - The code is functionally correct because `ACPI_FREE()` and `kfree()` are equivalent.
**For ACPICA coding standards: YES** - Memory allocated by ACPICA functions (like `acpi_evaluate_object_typed()`) should be freed using `ACPI_FREE()` to maintain consistency and support debugging builds.
### Pattern of Similar Fixes
Multiple commits have addressed this same issue: - `c00901e98b1e9`: "ACPI: pfr_update: use ACPI_FREE() to free acpi_object" - `ae3075b54fa8d`: "ACPI: pfr_telemetry: use ACPI_FREE() to free acpi_object" - `252f006676d1b`: "net: wwan: iosm: use ACPI_FREE() but not kfree()"
All cite the same rationale: "we need to track the allocation of acpi_object when ACPI_DBG_TRACK_ALLOCATIONS enabled"
### Why This Should Be Backported
1. **Code correctness**: Follows ACPICA conventions - allocation/deallocation should use matching functions 2. **Extremely low risk**: In the kernel, this is a no-op change since the functions are equivalent 3. **Consistency**: Part of a wider effort to fix this pattern across the kernel 4. **Debugging support**: Enables proper memory leak detection in ACPICA debugging tools 5. **Small, contained change**: Single line modification with no side effects 6. **Already backported**: This commit is itself a stable backport (upstream: `149139ddcb99`)
### Why This Has Low Priority
1. **No user-visible impact**: Does not fix crashes, data corruption, or functional bugs 2. **No security implications**: Not exploitable or security-related 3. **Cleanup/style fix**: Primarily about code correctness rather than fixing broken functionality
### Conclusion
This is a **low-priority correctness fix** suitable for backporting. While it doesn't fix a critical bug affecting users, it: - Maintains proper ACPICA coding standards - Has zero risk of regression (equivalent functions) - Aligns with a consistent pattern of similar fixes in stable trees - Improves code maintainability and debugging capability
The commit follows stable kernel rules by being a small, safe improvement with clear benefits and no downsides.
drivers/acpi/device_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 3961fc47152c0..cd199fbe4dc90 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -464,7 +464,7 @@ static ssize_t description_show(struct device *dev,
buf[result++] = '\n';
- kfree(str_obj); + ACPI_FREE(str_obj);
return result; }