All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails
@ 2026-07-31 16:18 Myeonghun Pak
  2026-07-31 16:18 ` [PATCH 2/2] tty: moxa: use pcim_enable_device() Myeonghun Pak
  2026-08-03  6:06 ` [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Jiri Slaby
  0 siblings, 2 replies; 5+ messages in thread
From: Myeonghun Pak @ 2026-07-31 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-kernel, stable, Myeonghun Pak, Ijae Kim

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")
Cc: stable@vger.kernel.org
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 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;
 }
-- 
2.47.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] tty: moxa: use pcim_enable_device()
  2026-07-31 16:18 [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Myeonghun Pak
@ 2026-07-31 16:18 ` Myeonghun Pak
  2026-08-03  6:06 ` [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Jiri Slaby
  1 sibling, 0 replies; 5+ messages in thread
From: Myeonghun Pak @ 2026-07-31 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-kernel, stable, Myeonghun Pak, Ijae Kim

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")
Cc: stable@vger.kernel.org
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 drivers/tty/moxa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 680b2dd65462..02220ecf3b38 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -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;
-- 
2.47.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails
  2026-07-31 16:18 [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Myeonghun Pak
  2026-07-31 16:18 ` [PATCH 2/2] tty: moxa: use pcim_enable_device() Myeonghun Pak
@ 2026-08-03  6:06 ` Jiri Slaby
  2026-08-03 12:41   ` Greg Kroah-Hartman
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Slaby @ 2026-08-03  6:06 UTC (permalink / raw)
  To: Myeonghun Pak, Greg Kroah-Hartman
  Cc: linux-serial, linux-kernel, stable, Ijae Kim

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/2da84e36-7ac6-407d-8e08-edca82f4cbce@kernel.org/

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails
  2026-08-03  6:06 ` [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Jiri Slaby
@ 2026-08-03 12:41   ` Greg Kroah-Hartman
  2026-08-04 13:55     ` Myeonghun Pak
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-08-03 12:41 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Myeonghun Pak, linux-serial, linux-kernel, stable, Ijae Kim

On Mon, Aug 03, 2026 at 08:06:58AM +0200, Jiri Slaby wrote:
> 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/2da84e36-7ac6-407d-8e08-edca82f4cbce@kernel.org/

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

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails
  2026-08-03 12:41   ` Greg Kroah-Hartman
@ 2026-08-04 13:55     ` Myeonghun Pak
  0 siblings, 0 replies; 5+ messages in thread
From: Myeonghun Pak @ 2026-08-04 13:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby, linux-serial, linux-kernel, stable, Ijae Kim

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 <gregkh@linuxfoundation.org>님이 작성:
>
> On Mon, Aug 03, 2026 at 08:06:58AM +0200, Jiri Slaby wrote:
> > 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/2da84e36-7ac6-407d-8e08-edca82f4cbce@kernel.org/
>
> I agree, I'll submit a patch to just drop it.
>
> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-04 13:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 16:18 [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Myeonghun Pak
2026-07-31 16:18 ` [PATCH 2/2] tty: moxa: use pcim_enable_device() Myeonghun Pak
2026-08-03  6:06 ` [PATCH 1/2] tty: moxa: unwind tty driver if PCI registration fails Jiri Slaby
2026-08-03 12:41   ` Greg Kroah-Hartman
2026-08-04 13:55     ` Myeonghun Pak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.