[PATCH AUTOSEL 6.19-5.10] media: cx25821: Fix a resource leak in cx25821_dev_setup()

Sasha Levin
2026-02-14T01:04:03Z

From: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>

[ Upstream commit 68cd8ac994cac38a305200f638b30e13c690753b ]

Add release_mem_region() if ioremap() fails to release the memory
region obtained by cx25821_get_resources().

Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Analysis of cx25821 Resource Leak Fix

### 1. Commit Message Analysis

The commit message is clear and direct: "Fix a resource leak in
cx25821_dev_setup()". It describes adding a `release_mem_region()` call
when `ioremap()` fails, to release the memory region previously obtained
by `cx25821_get_resources()`. This is a classic error-path resource leak
fix.

### 2. Code Change Analysis

The change is a **single line addition**:

```c
release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0));
```

**The bug mechanism:**
- `cx25821_get_resources()` is called earlier in `cx25821_dev_setup()`
and successfully acquires a memory region via `request_mem_region()`.
- Later, `ioremap()` is called. If `ioremap()` fails, the function
returns `-ENOMEM`.
- However, before this fix, the memory region obtained by
`cx25821_get_resources()` was **never released** on this error path.
- The existing `cx25821_iounmap(dev)` call handles unmapping but doesn't
release the memory region that was requested.

This is a textbook resource leak on an error path — one of the most
common and well-understood bug patterns in Linux kernel stable
backports.

### 3. Classification

- **Bug type**: Resource leak (memory region not released on error path)
- **Category**: Error path fix — fits squarely in the "cleanup that
fixes a real bug" pattern
- **Severity**: Medium — the leaked memory region would prevent the
resource from being reused until reboot, though this only triggers
when `ioremap()` fails (which is rare but real, especially under
memory pressure)

### 4. Scope and Risk Assessment

- **Lines changed**: 1 line added
- **Files touched**: 1 file (`drivers/media/pci/cx25821/cx25821-core.c`)
- **Risk**: Extremely low — adding a `release_mem_region()` call on a
failure path is well-understood and cannot cause any regression. It
only executes when `ioremap()` has already failed.
- **Subsystem**: PCI media driver (cx25821) — a specific video capture
card driver

### 5. User Impact

- The cx25821 is a Conexant video capture chipset used in real hardware.
Users of this hardware who encounter an `ioremap()` failure would have
a resource leak that prevents the memory region from being reclaimed.
- While the error condition (ioremap failure) is uncommon, when it does
occur, the resource leak is permanent until reboot.

### 6. Stability Indicators

- Signed off by Hans Verkuil, a well-known and experienced media
subsystem maintainer
- The fix is trivially correct — it matches the standard pattern for
releasing resources on error paths
- The change has no dependencies on other commits

### 7. Dependency Check

- The `release_mem_region()` function and the cx25821 driver have
existed for a very long time in the kernel
- No dependencies on newer code — this will apply cleanly to any stable
tree that contains the cx25821 driver

### 8. Stable Kernel Criteria

- **Obviously correct**: Yes — standard resource cleanup pattern
- **Fixes a real bug**: Yes — resource leak on error path
- **Small and contained**: Yes — 1 line, 1 file
- **No new features**: Correct — pure bug fix
- **Tested**: Accepted by subsystem maintainer

### Conclusion

This is a minimal, surgical fix for a resource leak on an error path. It
adds a single `release_mem_region()` call when `ioremap()` fails,
preventing a memory region from being leaked. The fix is obviously
correct, has zero regression risk, and follows a well-established
pattern. It meets all stable kernel criteria.

**YES**

drivers/media/pci/cx25821/cx25821-core.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/media/pci/cx25821/cx25821-core.c b/drivers/media/pci/cx25821/cx25821-core.c
index 6627fa9166d30..a7336be444748 100644
--- a/drivers/media/pci/cx25821/cx25821-core.c
+++ b/drivers/media/pci/cx25821/cx25821-core.c
@@ -908,6 +908,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)

if (!dev->lmmio) {
CX25821_ERR("ioremap failed, maybe increasing __VMALLOC_RESERVE in page.h\n");
+ release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0));
cx25821_iounmap(dev);
return -ENOMEM;
}
--
2.51.0