Skip to contentSkip to conversation

tty: moxa: unwind tty driver if PCI registration fails

PATCH In review Myeonghun Pak 3 participants 5 messages Jul 31 – Aug 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tty: moxa: unwind tty driver if PCI registration fails

moxa_init() registers the tty driver before registering the PCI driver. If pci_register_driver() fails, module initialization returns without unregistering the tty driver or dropping its reference. moxa_exit() is not called after a failed module initialization.

Unregister the tty driver and drop its reference before returning the PCI registration error.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes a784bf7c195f ("[PATCH] Char: moxa, pci probing")
---
 drivers/tty/moxa.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/moxa.c +4 -1
index 1bb2376af85c..680b2dd65462 100644
@@ -1172,8 +1172,11 @@ static int __init moxa_init(void)
 	}
 
 	retval = pci_register_driver(&moxa_pci_driver);
-	if (retval)
+	if (retval) {
 		printk(KERN_ERR "Can't register MOXA pci driver!\n");
+		tty_unregister_driver(moxaDriver);
+		tty_driver_kref_put(moxaDriver);
+	}
 
 	return retval;
 }
Signature · 1 line
2.47.1
#1 lore raw

PATCH 2/2 tty: moxa: use pcim_enable_device()

moxa_pci_probe() enables the PCI device with pci_enable_device(), but its failure paths and remove callback do not disable it. Repeated bind and unbind cycles can therefore leave the PCI enable count unbalanced.

Use pcim_enable_device() so the PCI core automatically disables the device when probe fails or the driver detaches. Keep the existing explicit BAR request and mapping cleanup unchanged.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/tty/moxa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/moxa.c +1 -1
index 680b2dd65462..02220ecf3b38 100644
@@ -1063,7 +1063,7 @@ static int moxa_pci_probe(struct pci_dev *pdev,
 	int board_type = ent->driver_data;
 	int retval;
 
-	retval = pci_enable_device(pdev);
+	retval = pcim_enable_device(pdev);
 	if (retval) {
 		dev_err(&pdev->dev, "can't enable pci device\n");
 		goto err;
Signature · 1 line
2.47.1
maintainer
#2 lore raw
In reply to Myeonghun Pak
Quoted 7 lines · Myeonghun Pak

moxa_init() registers the tty driver before registering the PCI driver. If pci_register_driver() fails, module initialization returns without unregistering the tty driver or dropping its reference. moxa_exit() is not called after a failed module initialization.

Unregister the tty driver and drop its reference before returning the PCI registration error.

I think, we should remove the whole driver instead:
https://lore.kernel.org/all/[email protected]/

Quoted 21 lines
---
  drivers/tty/moxa.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/moxa.c +4 -1
index 1bb2376af85c..680b2dd65462 100644
@@ -1172,8 +1172,11 @@ static int __init moxa_init(void)
  	}
 
  	retval = pci_register_driver(&moxa_pci_driver);
-	if (retval)
+	if (retval) {
  		printk(KERN_ERR "Can't register MOXA pci driver!\n");
+		tty_unregister_driver(moxaDriver);
+		tty_driver_kref_put(moxaDriver);
+	}
 
  	return retval;
  }
Signature · 2 lines
js
suse labs
#3 lore raw
Quoted 10 lines · Jiri Slaby
Quoted 7 lines · Myeonghun Pak

moxa_init() registers the tty driver before registering the PCI driver. If pci_register_driver() fails, module initialization returns without unregistering the tty driver or dropping its reference. moxa_exit() is not called after a failed module initialization.

Unregister the tty driver and drop its reference before returning the PCI registration error.

I think, we should remove the whole driver instead:
https://lore.kernel.org/all/[email protected]/

I agree, I'll submit a patch to just drop it.

thanks,

greg k-h

#4 lore raw

Hi Jiri and Greg,

Thanks for the review. I agree that removing the whole MOXA driver is the better direction, which supersedes this patch. Please drop/ignore this patch.

Best regards,
Myeonghun

2026년 8월 3일 (월) 오후 9:41, Greg Kroah-Hartman <[email protected]>님이 작성:

Quoted 18 lines · Jiri Slaby
Quoted 10 lines · Myeonghun Pak
Quoted 7 lines

moxa_init() registers the tty driver before registering the PCI driver. If pci_register_driver() fails, module initialization returns without unregistering the tty driver or dropping its reference. moxa_exit() is not called after a failed module initialization.

Unregister the tty driver and drop its reference before returning the PCI registration error.

I think, we should remove the whole driver instead:
https://lore.kernel.org/all/[email protected]/

I agree, I'll submit a patch to just drop it.

thanks,

greg k-h