From: Krzysztof Kozlowski krzysztof.kozlowski@linaro.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@linaro.org Link: https://lore.kernel.org/r/20250406202730.55096-2-krzysztof.kozlowski@linaro.... Signed-off-by: Sebastian Reichel sebastian.reichel@collabora.com Signed-off-by: Sasha Levin sashal@kernel.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@vger.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; }