serial: qcom-geni: Avoid double-free of PM domain list
Subsystems (2)
PATCH 1/1 serial: qcom-geni: Avoid double-free of PM domain list
The SA8255P UART variants attach PM domains through devm_pm_domain_attach_list(), which registers a devres cleanup action to detach and free the PM domain list automatically on probe failure or device removal.
Remove the manual dev_pm_domain_detach_list() calls from the probe error path and remove callback. These calls can operate on memory that has already been freed by the devres-managed cleanup, resulting in a potential double-free. Also remove the unused pm_domain.h header.
--- drivers/tty/serial/qcom_geni_serial.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +0 -4
@@ -20,7 +20,6 @@#include <linux/module.h> #include <linux/of.h> #include <linux/panic_notifier.h> -#include <linux/pm_domain.h> #include <linux/pm_opp.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h>
@@ -2008,7 +2007,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) DMA_RX_BUF_SIZE, DMA_FROM_DEVICE); port->rx_dma_addr =0 ; } -dev_pm_domain_detach_list (port->se.pd_list);return ret; }
@@ -2032,8 +2030,6 @@ static void qcom_geni_serial_remove(struct platform_device *pdev) DMA_RX_BUF_SIZE, DMA_FROM_DEVICE); port->rx_dma_addr =0 ; } - -dev_pm_domain_detach_list (port->se.pd_list); }static int __maybe_unused qcom_geni_serial_runtime_suspend (struct device *dev)
---
base-commit: 89c07d98716a13454ec3fd9f97689e812cc71bd4
change-id: 20260901-probe_cleanup_uart-60bb7d0df5ae
Best regards,
Signature · 1 line
Aniket Randive <[email protected]>
Hi
Quoted 37 lines · Aniket Randive
The SA8255P UART variants attach PM domains through
devm_pm_domain_attach_list(), which registers a devres cleanup action to detach and free the PM domain list automatically on probe failure or device removal.Remove the manual
dev_pm_domain_detach_list()calls from the probe error path and remove callback. These calls can operate on memory that has already been freed by the devres-managed cleanup, resulting in a potential double-free. Also remove the unusedpm_domain.hheader.Suggested-by Konrad Dybcio <[email protected]>Signed-off-by Aniket Randive <[email protected]>--- drivers/tty/serial/qcom_geni_serial.c | 4 ---- 1 file changed, 4 deletions(-)drivers/tty/serial/qcom_geni_serial.c +0
-2@@ -20,7 +20,6 @@#include <linux/module.h> #include <linux/of.h> #include <linux/panic_notifier.h> -#include <linux/pm_domain.h> #include <linux/pm_opp.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> @@ -2008,7 +2007,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) DMA_RX_BUF_SIZE, DMA_FROM_DEVICE); port->rx_dma_addr =0 ; } -dev_pm_domain_detach_list (port->se.pd_list);return ret; }
drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_remove(struct platform_device *pdev) · line 2034
Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c +0
-2@@ -2032,8 +2030,6 @@ static void qcom_geni_serial_remove(struct platform_device *pdev) DMA_RX_BUF_SIZE, DMA_FROM_DEVICE); port->rx_dma_addr =0 ; } - -dev_pm_domain_detach_list (port->se.pd_list); }
Thanks,
Praveen Talari
Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c +0
-1static int __maybe_unused qcom_geni_serial_runtime_suspend (struct device *dev) ---base-commit:
89c07d98716a13454ec3fd9f97689e812cc71bd4
change-id: 20260901-probe_cleanup_uart-60bb7d0df5aeBest regards,
--
Aniket Randive <[email protected]>
Quoted 5 lines · Aniket Randive
The SA8255P UART variants attach PM domains through
devm_pm_domain_attach_list(), which registers a devres cleanup action to detach and free the PM domain list automatically on probe failure or device removal.
Quoted 8 lines
Remove the manual
dev_pm_domain_detach_list()calls from the probe error path and remove callback. These calls can operate on memory that has already been freed by the devres-managed cleanup, resulting in a potential double-free. Also remove the unusedpm_domain.hheader.Suggested-by Konrad Dybcio <[email protected]>Signed-off-by Aniket Randive <[email protected]>---
Konrad
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Asynchronous pm_runtime_put() immediately followed by devres-managed pm_runtime_disable() on probe error path.
- [High] Probe error paths leak IDA slots and dedicated wake IRQs, and ida_free() crashes on console unbind. --
commit 70e27637a93cd696a967e44f11424854b0e2411a
Author: Aniket Randive <[email protected]>
serial: qcom-geni: Avoid double-free of PM domain list
The SA8255P UART variants attach PM domains through devm_pm_domain_attach_list(), which registers a devres cleanup action to detach and free the PM domain list automatically on probe failure or device removal.
Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c +0
-0
[ ... ]
drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 2011
Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c +0
-1@@ -2008,7 +2007,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) DMA_RX_BUF_SIZE, DMA_FROM_DEVICE); port->rx_dma_addr =0 ; } -dev_pm_domain_detach_list (port->se.pd_list);return ret; }
[Severity: High]
This isn't a bug introduced by this patch, but does the error path in qcom_geni_serial_probe() fail to release several resources?
If uart_add_one_port() or pm_runtime_resume_and_get() fail in probe, the code jumps to the error label which completely fails to call ida_free(), dev_pm_clear_wake_irq(), and device_init_wakeup(..., false).
Additionally, if devm_kzalloc() fails earlier in get_port_from_line() in the same file, the allocated IDA slot is never freed, resulting in a permanent leak of global IDA slots.
[Severity: High]
This is a pre-existing issue, but does the asynchronous pm_runtime_put() on the probe error path leave the hardware permanently powered on?
drivers/tty/serial/qcom_geni_serial.c:qcom_geni_serial_probe() {
...
ret = uart_add_one_port(drv, uport);
pm_runtime_put(uport->dev);
if (ret)
goto error;
...
}If uart_add_one_port() fails, pm_runtime_put() queues an asynchronous suspend right before returning. Because this is an error path, devres will immediately invoke pm_runtime_disable() which cancels the pending asynchronous idle/suspend work, leaking power.
drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_remove(struct platform_device *pdev) · line 2033
Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c +0
-2@@ -2032,8 +2030,6 @@ static void qcom_geni_serial_remove(struct platform_device *pdev) DMA_RX_BUF_SIZE, DMA_FROM_DEVICE); port->rx_dma_addr =0 ; } - -dev_pm_domain_detach_list (port->se.pd_list); }
[Severity: High]
This is a pre-existing issue, but does the unconditional ida_free() in qcom_geni_serial_remove() trigger a warning when unbinding console ports?
drivers/tty/serial/qcom_geni_serial.c:qcom_geni_serial_remove() {
...
ida_free(&port_ida, uport->line);
...
}When unbinding the driver for a console port, ida_free() is called on a port line that was statically assigned, not allocated from the IDA, which causes a WARN_ON_ONCE.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 5 lines · Aniket Randive
The SA8255P UART variants attach PM domains through
devm_pm_domain_attach_list(), which registers a devres cleanup action to detach and free the PM domain list automatically on probe failure or device removal.
Quoted 7 lines
Remove the manual
dev_pm_domain_detach_list()calls from the probe error path and remove callback. These calls can operate on memory that has already been freed by the devres-managed cleanup, resulting in a potential double-free. Also remove the unusedpm_domain.hheader.Suggested-by Konrad Dybcio <[email protected]>Signed-off-by Aniket Randive <[email protected]>