Skip to contentSkip to conversation

serial: core: fix OF node leak

PATCH In review Johan Hovold 3 participants 4 messages Jul 8, 2025 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: core: fix OF node leak

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 <[email protected]>
---
 drivers/tty/serial/serial_base_bus.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tty/serial/serial_base_bus.c +3 -0
index cb3b127b06b6..22749ab0428a 100644
@@ -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(struct device *dev)
 {
 	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(struct device *dev)
 {
 	struct serial_port_device *port_dev = to_serial_base_port_device(dev);
 
+	of_node_put(dev->of_node);
 	kfree(port_dev);
 }
 
Signature · 1 line
2.49.0
#1 lore raw

Hi Johan,

Quoted 48 lines · Johan Hovold

CAUTION: This email originated from outside the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

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")

---
 drivers/tty/serial/serial_base_bus.c | 3 +++

 1 file changed, 3 insertions(+)
drivers/tty/serial/serial_base_bus.c +1 -0
index cb3b127b06b6..22749ab0428a 100644
@@ -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(struct device
 *dev)
  {

        struct serial_ctrl_device *ctrl_dev =
to_serial_base_ctrl_device(dev);

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

drivers/tty/serial/serial_base_bus.c +0 -0
@@ -140,6 +142,7 @@ static void serial_base_port_release(struct device
 *dev)
  {

        struct serial_port_device *port_dev =
to_serial_base_port_device(dev);

Quoted 6 lines

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

--
2.49.0

Thanks for the fix. I think this also needs to go into -stable, as the previous changes have already landed there (6.12.36 and 6.15.5).

Aidan

#2 lore raw
Quoted 5 lines · Aidan Stewart
Quoted 3 lines · Johan Hovold

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

Quoted 7 lines
Quoted 4 lines
Fixes d36f0e9a0002 ("serial: core: restore of_node information in

sysfs")

Thanks for the fix. I think this also needs to go into -stable, as the previous changes have already landed there (6.12.36 and 6.15.5).

I left out the stable tag on purpose since this leak should not cause trouble as, for example, these devices are typically registered at boot and never deregistered.

It fixes an issue introduced in rc4 so it should preferably still go into 6.16-final, though.

Johan

#3 lore raw
Quoted 14 lines · Johan Hovold
Quoted 5 lines · Aidan Stewart
Quoted 3 lines · Johan Hovold

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

Quoted 7 lines
Quoted 4 lines
Fixes d36f0e9a0002 ("serial: core: restore of_node information in

sysfs")

Thanks for the fix. I think this also needs to go into -stable, as the previous changes have already landed there (6.12.36 and 6.15.5).

Quoted 6 lines

I left out the stable tag on purpose since this leak should not cause trouble as, for example, these devices are typically registered at boot and never deregistered.

It fixes an issue introduced in rc4 so it should preferably still go into 6.16-final, though.

Ok, will get this merged, thanks!

greg k-h