public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Lee Jones <lee@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 6.15 08/21] mfd: max77541: Fix wakeup source leaks on device unbind
Date: Fri,  6 Jun 2025 11:41:33 -0400	[thread overview]
Message-ID: <20250606154147.546388-8-sashal@kernel.org> (raw)
In-Reply-To: <20250606154147.546388-1-sashal@kernel.org>

From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

[ Upstream commit 6c7115cdf6440e1e2f15e21efe92e2b757940627 ]

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/20250406-mfd-device-wakekup-leak-v1-4-318e14bdba0a@linaro.org
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

Perfect! Now I have all the information I need to make a comprehensive
analysis.

**YES**

This commit should be backported to stable kernel trees.

**Extensive Analysis:**

**1. Nature of the Bug:**
The commit fixes a wakeup source memory leak that occurs when the
max77541 MFD device is unbound. The current code in
`max77541_pmic_setup()` at line 155 calls `device_init_wakeup(dev,
true)` to enable wakeup capability, but there's no corresponding cleanup
when the device is removed.

**2. Code Change Analysis:**
The fix replaces:
```c
ret = device_init_wakeup(dev, true);
```
with:
```c
ret = devm_device_init_wakeup(dev);
```

This is a classic resource management improvement. The
`devm_device_init_wakeup()` function (as seen in
`/home/sasha/linux/include/linux/pm_wakeup.h`) automatically registers a
cleanup action via `devm_add_action_or_reset()` that calls
`device_disable_wakeup()` when the device is removed, preventing the
memory leak.

**3. Driver Context:**
- The max77541 driver was introduced in April 2023 (commit e0cbc202388a)
- It's an I2C-based MFD driver for MAX77541/MAX77540 PMICs
- The driver has **no remove function** (line 213-214 shows only
  `.probe` in the driver structure), making this cleanup particularly
  important since only devm-managed resources will be cleaned up
  automatically
- The driver uses devm-managed functions extensively (devm_kzalloc,
  devm_regmap_init_i2c, devm_mfd_add_devices), showing this change fits
  the existing pattern

**4. Comparison with Similar Commits:**
This commit follows the exact same pattern as the "YES" backport
examples:
- **Similar Commit #1 (gpio-mpc8xxx.c)**: Same fix pattern, same wakeup
  leak issue, marked YES for backport with explicit `Cc:
  stable@vger.kernel.org`
- **Similar Commit #2 (gpio-zynq.c)**: Same fix pattern, same wakeup
  leak issue, marked YES for backport with explicit `Cc:
  stable@vger.kernel.org`

The change is identical in nature to these GPIO drivers that were deemed
suitable for stable backporting.

**5. Stable Tree Criteria Assessment:**
- ✅ **Fixes important bug**: Memory leaks affect system stability over
  time
- ✅ **Small and contained**: Single line change, minimal risk
- ✅ **No architectural changes**: Uses existing devm infrastructure
- ✅ **No new features**: Pure bugfix
- ✅ **Minimal regression risk**: devm_device_init_wakeup() is well-
  established and widely used
- ✅ **Clear benefit**: Prevents resource leaks in production systems

**6. Impact and Risk Assessment:**
- **Impact**: Prevents memory leaks when max77541 devices are unbound
  (e.g., module unload, device removal, system suspend/resume cycles)
- **Risk**: Extremely low - the devm framework is mature and this
  pattern is used extensively across the kernel
- **Regression potential**: Minimal - the functionality remains
  identical, just with proper cleanup

**7. Subsystem Considerations:**
The MFD subsystem handles critical power management ICs. Memory leaks in
power management drivers can lead to system instability, especially in
embedded systems where the max77541 PMIC would typically be used.

This is a textbook example of a stable-worthy commit: it fixes a real
resource management bug with a minimal, well-tested change that follows
established kernel patterns.

 drivers/mfd/max77541.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/max77541.c b/drivers/mfd/max77541.c
index d77c31c86e435..f91b4f5373ce9 100644
--- a/drivers/mfd/max77541.c
+++ b/drivers/mfd/max77541.c
@@ -152,7 +152,7 @@ static int max77541_pmic_setup(struct device *dev)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to initialize IRQ\n");
 
-	ret = device_init_wakeup(dev, true);
+	ret = devm_device_init_wakeup(dev);
 	if (ret)
 		return dev_err_probe(dev, ret, "Unable to init wakeup\n");
 
-- 
2.39.5


  parent reply	other threads:[~2025-06-06 15:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06 15:41 [PATCH AUTOSEL 6.15 01/21] cifs: Correctly set SMB1 SessionKey field in Session Setup Request Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 02/21] cifs: Fix cifs_query_path_info() for Windows NT servers Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 03/21] cifs: Fix encoding of SMB1 Session Setup NTLMSSP Request in non-UNICODE mode Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 04/21] NFSv4: Always set NLINK even if the server doesn't support it Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 05/21] NFSv4.2: fix listxattr to return selinux security label Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 06/21] NFSv4.2: fix setattr caching of TIME_[MODIFY|ACCESS]_SET when timestamps are delegated Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 07/21] mailbox: Not protect module_put with spin_lock_irqsave Sasha Levin
2025-06-06 15:41 ` Sasha Levin [this message]
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 09/21] mfd: max14577: Fix wakeup source leaks on device unbind Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 10/21] mfd: max77705: " Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 11/21] mfd: 88pm886: " Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 12/21] mfd: sprd-sc27xx: " Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 13/21] sunrpc: don't immediately retransmit on seqno miss Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 14/21] hwmon: (isl28022) Fix current reading calculation Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 15/21] dm vdo indexer: don't read request structure after enqueuing Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 16/21] leds: multicolor: Fix intensity setting while SW blinking Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 17/21] fuse: fix race between concurrent setattrs from multiple nodes Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 18/21] cxl/region: Add a dev_err() on missing target list entries Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 19/21] cxl: core/region - ignore interleave granularity when ways=1 Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 20/21] NFSv4: xattr handlers should check for absent nfs filehandles Sasha Levin
2025-06-06 15:41 ` [PATCH AUTOSEL 6.15 21/21] hwmon: (pmbus/max34440) Fix support for max34451 Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250606154147.546388-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=lee@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox