From: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org
[ Upstream commit 37ef4aa4039c42f4b15dc7e40d3e437b7f031522 ]
Device can be unbound, so driver must also release memory for the wakeup source.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org Reviewed-by: Baolin Wang baolin.wang@linux.alibaba.com Link: https://lore.kernel.org/r/20250406-mfd-device-wakekup-leak-v1-8-318e14bdba0a... Signed-off-by: Lee Jones lee@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org ---
**YES**
This commit should be backported to stable kernel trees. Here's my detailed analysis:
## Resource Leak Analysis
The commit fixes a genuine resource leak in the sprd-sc27xx MFD driver. When `device_init_wakeup(&spi->dev, true)` is called in the probe function (line 213), it:
1. **Allocates kernel resources**: Creates wakeup source objects and sysfs entries 2. **Sets device capability flags**: Marks the device as wakeup-capable 3. **Registers with PM subsystem**: Adds the device to power management tracking
However, the driver **lacks a remove function** to clean up these resources when the device is unbound.
## Code Change Analysis
The fix changes from: ```c device_init_wakeup(&spi->dev, true); ```
To: ```c ret = devm_device_init_wakeup(&spi->dev); if (ret) return dev_err_probe(&spi->dev, ret, "Failed to init wakeup\n"); ```
This uses the **managed version** (`devm_device_init_wakeup`) which automatically calls cleanup when the device is removed, eliminating the leak.
## Backport Justification
**1. Bug Fix Nature**: This addresses a clear resource leak affecting production systems with removable devices or driver reloading scenarios.
**2. Minimal Risk**: The change is contained to a single function call with identical functionality, just with automatic cleanup.
**3. Critical Subsystem**: MFD drivers control PMICs (Power Management ICs), which are essential for power management and system stability.
**4. Pattern Consistency**: The fix follows the same pattern as the approved similar commits for gpio drivers (mpc8xxx and zynq), which were both marked for backporting.
**5. Clear Impact**: Resource leaks in device drivers can accumulate over time and affect system stability, especially in embedded systems where this PMIC driver is commonly used.
**6. Small, Contained Change**: The modification is minimal and self- contained, reducing regression risk.
The commit clearly states the problem, provides a proper solution using managed resources, and affects a driver commonly used in production embedded systems where resource leaks can be particularly problematic.
drivers/mfd/sprd-sc27xx-spi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/sprd-sc27xx-spi.c b/drivers/mfd/sprd-sc27xx-spi.c index 7186e2108108f..d6b4350779e6a 100644 --- a/drivers/mfd/sprd-sc27xx-spi.c +++ b/drivers/mfd/sprd-sc27xx-spi.c @@ -210,7 +210,10 @@ static int sprd_pmic_probe(struct spi_device *spi) return ret; }
- device_init_wakeup(&spi->dev, true); + ret = devm_device_init_wakeup(&spi->dev); + if (ret) + return dev_err_probe(&spi->dev, ret, "Failed to init wakeup\n"); + return 0; }