[PATCH 6.12 498/567] serial: core: fix OF node leak

Greg Kroah-Hartman
2026-01-06T17:43:37Z

From: Johan Hovold <johan@kernel.org>

[ Upstream commit 273cc3406c8d4e830ed45967c70d08d20ca1380e ]

Make sure to drop the OF node reference taken when initialising the
control and port devices when the devices are later released.

Fixes: d36f0e9a0002 ("serial: core: restore of_node information in sysfs")
Cc: Aidan Stewart <astewart@tektelic.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20250708085817.16070-1-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: 24ec03cc5512 ("serial: core: Restore sysfs fwnode information")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/tty/serial/serial_base_bus.c | 3 +++
1 file changed, 3 insertions(+)

--- a/drivers/tty/serial/serial_base_bus.c
+++ b/drivers/tty/serial/serial_base_bus.c
@@ -13,6 +13,7 @@
#include <linux/device.h>
#include <linux/idr.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/serial_core.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
@@ -93,6 +94,7 @@ static void serial_base_ctrl_release(str
{
struct serial_ctrl_device *ctrl_dev = to_serial_base_ctrl_device(dev);

+ of_node_put(dev->of_node);
kfree(ctrl_dev);
}

@@ -140,6 +142,7 @@ static void serial_base_port_release(str
{
struct serial_port_device *port_dev = to_serial_base_port_device(dev);

+ of_node_put(dev->of_node);
kfree(port_dev);
}