[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250530123934.2574748-4-sashal@kernel.org>
Date: Fri, 30 May 2025 08:39:10 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
stable@...r.kernel.org
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>,
Sebastian Reichel <sebastian.reichel@...labora.com>,
Sasha Levin <sashal@...nel.org>,
sre@...nel.org,
linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH AUTOSEL 6.14 04/28] power: supply: gpio-charger: Fix wakeup source leaks on device unbind
From: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
[ Upstream commit 51212ce95354c5b51e8c3054bf80eeeed80003b6 ]
Device can be unbound, so driver must also release memory for the wakeup
source.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
Link: https://lore.kernel.org/r/20250406202730.55096-2-krzysztof.kozlowski@linaro.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@...labora.com>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
**YES** This commit should be backported to stable kernel trees.
**Detailed Analysis:** **1. Bug Fix Nature:** This commit fixes a
resource leak bug where wakeup sources are not properly cleaned up when
the device is unbound. The original code calls `device_init_wakeup(dev,
1)` but has no corresponding cleanup in the remove path, leading to
memory leaks. **2. Code Changes Analysis:** The fix replaces: ```c
device_init_wakeup(dev, 1); ``` with: ```c ret =
devm_device_init_wakeup(dev); if (ret) return dev_err_probe(dev, ret,
"Failed to init wakeup\n"); ``` The `devm_device_init_wakeup()` function
automatically manages the wakeup source lifecycle using the device
resource management system (`devm_add_action_or_reset()`), ensuring
proper cleanup when the device is removed. **3. Comparison with Similar
Commits:** This commit is nearly identical to the reference commits #1
and #2 (both marked "YES" for backporting): - **Similar Commit #1 (gpio:
mpc8xxx)**: Same exact pattern - replacing `device_init_wakeup(dev,
true)` with `devm_device_init_wakeup(dev)` - **Similar Commit #2 (gpio:
zynq)**: Adds `device_init_wakeup(&pdev->dev, 0)` in remove function -
Both were explicitly marked for stable with `Cc: stable@...r.kernel.org`
**4. Stable Tree Criteria Met:** - ✅ **Important bugfix**: Fixes
resource leaks that affect system stability - ✅ **Small and contained**:
Only 4 lines changed, very focused fix - ✅ **Minimal regression risk**:
Uses well-established devm pattern - ✅ **No architectural changes**:
Simple resource management improvement - ✅ **Clear side effects**: None
beyond fixing the leak **5. Technical Correctness:** The
`devm_device_init_wakeup()` function automatically calls
`device_init_wakeup(dev, false)` during device cleanup via the devm
framework. This is the standard pattern for managing wakeup sources in
modern kernel drivers. **6. Impact Assessment:** Resource leaks can
accumulate over time, especially in systems where devices are frequently
bound/unbound (like USB devices, hot-pluggable hardware). This fix
prevents potential memory exhaustion and system instability. The commit
follows the exact same pattern as other accepted backports for identical
wakeup source leak fixes, making it a clear candidate for stable tree
inclusion.
drivers/power/supply/gpio-charger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
index 46d18ce6a7392..7aafb5189571b 100644
--- a/drivers/power/supply/gpio-charger.c
+++ b/drivers/power/supply/gpio-charger.c
@@ -366,7 +366,9 @@ static int gpio_charger_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, gpio_charger);
- device_init_wakeup(dev, 1);
+ ret = devm_device_init_wakeup(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to init wakeup\n");
return 0;
}
--
2.39.5
Powered by blists - more mailing lists