[PATCH] media: ti: cal: use devm regmap for camerrx fallback
From: Wang Haoran
Date: Thu Nov 19 2026 - 03:15:22 EST
cal_init_camerarx_regmap() builds the CAMERARX syscon with a plain
regmap_init_mmio() in the legacy fallback path and nothing ever calls
regmap_exit() on it, so any later probe failure leaks the regmap and its
debugfs entry. The fallback is precisely the tolerant path used with older
device trees, and defer retries or unbind/bind cycles stack one leak per
attempt.
Use devm_regmap_init_mmio() so the regmap is released on probe failure and
on removal.
Signed-off-by: Wang Haoran <wanghr2026@xxxxxxxxxxxxxxxxxx>
Fixes: 8148baabd1c4 ("media: platform: re-structure TI drivers")
---
diff --git a/drivers/media/platform/ti/cal/cal.c b/drivers/media/platform/ti/cal/cal.c
index c3c1073739a5..460d3e5f14d1 100644
--- a/drivers/media/platform/ti/cal/cal.c
+++ b/drivers/media/platform/ti/cal/cal.c
@@ -1123,7 +1123,7 @@ static int cal_init_camerarx_regmap(struct cal_dev *cal)
config.val_bits = 32;
config.max_register = resource_size(res) - 4;
- syscon = regmap_init_mmio(NULL, base, &config);
+ syscon = devm_regmap_init_mmio(cal->dev, base, &config);
if (IS_ERR(syscon)) {
pr_err("regmap init failed\n");
return PTR_ERR(syscon);
---
PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):
Device tree injection, spliced into the QEMU virt machine DT:
fck96m: clock-96m { compatible = "fixed-clock"; #clock-cells = <0>;
clock-frequency = <96000000>; };
reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;
cal-regs@7f300000 { no-map; reg = <0x0 0x7f300000 0x0 0x2000>; };
cal-camerrx@7f310000 { no-map; reg = <0x0 0x7f310000 0x0 0x1000>; }; };
cal@7f300000 { compatible = "ti,dra72-cal";
reg = <0x0 0x7f300000 0x0 0x1000>, <0x0 0x7f310000 0x0 0x1000>;
reg-names = "cal_top", "camerrx_control";
interrupt-parent = <&gpio0>; interrupts = <6 2>;
clocks = <&fck96m>; clock-names = "fck"; };
No ti,camerrx-control phandle is present, so the legacy fallback runs and
creates the camerrx regmap; the probe then fails later in camerrx creation.
Trigger:
modprobe ti-cal
Result:
cal 7f300000.cal: failed to get ti,camerrx-control: -ENOENT
cal 7f300000.cal: Unexpected CAL HW revision 0x00000000
cal 7f300000.cal: probe with driver cal failed with error -22
The dummy0 regmap entry remains in debugfs/regmap after the failed probe.
Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. The device tree is trusted input (a bad DT
requires root or physical access), so this is not a security fix, but it
prevents a potential resource leak or system failure on a failed probe or
an old or malformed DT.