serial: sh-sci: Unregister UART on sysfs setup failure
PATCH 1/1 serial: sh-sci: Unregister UART on sysfs setup failure
sci_probe_single() registers the UART port before sci_probe() creates the RX FIFO tuning attributes. If either device_create_file() call fails, probe returns an error without removing the port from the serial core. Device-managed resources are then released while the port remains registered.
Unregister the UART port before returning either sysfs creation error. If the second attribute fails, remove the first attribute before unregistering the port. Keep the existing probe failure policy and leave the successful initialization path unchanged.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/tty/serial/sh-sci.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tty/serial/sh-sci.c +6 -2
@@ -3937,12 +3937,12 @@ static int sci_probe(struct platform_device *dev)if (sp->port.fifosize >1 ) { ret =device_create_file (&dev->dev, &dev_attr_rx_fifo_trigger);if (ret) -return ret; + goto err_remove_port; ret =device_create_file (&dev->dev, &dev_attr_rx_fifo_timeout);if (ret) {device_remove_file (&dev->dev, &dev_attr_rx_fifo_trigger); -return ret; + goto err_remove_port; } }
@@ -3952,6 +3952,10 @@ static int sci_probe(struct platform_device *dev) sci_ports_in_use |=BIT (dev_id);return 0 ; + +err_remove_port: +uart_remove_one_port (&sci_uart_driver, &sp->port); +return ret; }static int sci_suspend (struct device *dev)
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
sci_probe_single()registers the UART port beforesci_probe()creates the RX FIFO tuning attributes. If eitherdevice_create_file()call fails, probe returns an error without removing the port from the serial core. Device-managed resources are then released while the port remains registered.Unregister the UART port before returning either sysfs creation error. If the second attribute fails, remove the first attribute before unregistering the port. Keep the existing probe failure policy and leave the successful initialization path unchanged.
Quoted 7 lines
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
Fixes 5d23188a473d ("serial: sh-sci: make RX FIFO parameters tunable via sysfs")Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1