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

Jiri Slaby <[email protected]> Mon, 3 Aug 2026 08:06:58 +0200
Newsgroups org.kernel.vger.linux-serial,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
On 31. 07. 26, 18:18, Myeonghun Pak wrote:
> 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]/

> ---
>   drivers/tty/moxa.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
> index 1bb2376af85c..680b2dd65462 100644
> --- a/drivers/tty/moxa.c
> +++ b/drivers/tty/moxa.c
> @@ -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;
>   }


-- 
js
suse labs