mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@kernel.org>
To: "Guenter Roeck" <linux@roeck-us.net>,
	"Niklas Schnelle" <schnelle@linux.ibm.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-serial@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	linux-kernel@vger.kernel.org,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH 1/1] tty: serial: handle HAS_IOPORT dependencies
Date: Fri, 22 Nov 2024 23:51:38 +0100	[thread overview]
Message-ID: <eb1c5d4b-0662-41dd-826c-d3c3cf78de2b@app.fastmail.com> (raw)
In-Reply-To: <791f37f3-2b93-47f1-b0a3-46825c09f222@roeck-us.net>

On Fri, Nov 22, 2024, at 21:44, Guenter Roeck wrote:
> On 11/22/24 11:24, Arnd Bergmann wrote:
>> 
>> serial8250_setup_port() is where it ends up using the
>> uninitialized serial8250_ports[index] contents. Since
>> port->iotype is not set to anything here, it defaults to
>> '0', which happens to be UPIO_PORT.
>> 
>> The reason it doesn't immediately crash and burn is that
>> this is still only setting up the structures for later
>> use, but I assume that trying to use console=ttyS0, or
>> opening /dev/ttyS0 on the uninitialized port would
>> then cause an oops.
>> 
>
> All four affected platforms use ttyS0, only it is mmio based,
> not io port based.

Right, so I think the problem is really the 8250_platform.c
file trying to handle all possible cases on x86 (acpi,
isapnp, legacy isa) that may define the same UARTs, but
also trying to handle non-legacy ports with their own
special cases on other architectures.

The patch below is a first idea of how we can skip the
legacy ISA case on architectures that don't define those.
If this works, we can try to come up with a better way of
doing that. Ideally all the pre-DT boardfile machines that
define their own "serial8250" platform_device (with platform_data)
should use a different identifier the x86-legacy case that
uses the platform_device (without platform_data). Similarly,
I think the riscv special ACPI port needs its own trivial
driver without all the ISA magic.

      Arnd

diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
index 66fd6d5d4835..610b31517734 100644
--- a/drivers/tty/serial/8250/8250_platform.c
+++ b/drivers/tty/serial/8250/8250_platform.c
@@ -101,7 +101,8 @@ static void __init __serial8250_isa_init_ports(void)
 
 void __init serial8250_isa_init_ports(void)
 {
-	DO_ONCE(__serial8250_isa_init_ports);
+	if (ARRAY_SIZE(old_serial_port))
+		DO_ONCE(__serial8250_isa_init_ports);
 }
 
 /*
@@ -283,7 +284,7 @@ static const struct acpi_device_id acpi_platform_serial_table[] = {
 };
 MODULE_DEVICE_TABLE(acpi, acpi_platform_serial_table);
 
-static struct platform_driver serial8250_isa_driver = {
+static struct platform_driver serial8250_platform_driver = {
 	.probe		= serial8250_probe,
 	.remove		= serial8250_remove,
 	.suspend	= serial8250_suspend,
@@ -300,7 +301,7 @@ static struct platform_driver serial8250_isa_driver = {
  */
 struct platform_device *serial8250_isa_devs;
 
-static int __init serial8250_init(void)
+static int __init serial8250_isa_init(void)
 {
 	int ret;
 
@@ -337,11 +338,8 @@ static int __init serial8250_init(void)
 
 	serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
 
-	ret = platform_driver_register(&serial8250_isa_driver);
-	if (ret == 0)
-		goto out;
+	return 0;
 
-	platform_device_del(serial8250_isa_devs);
 put_dev:
 	platform_device_put(serial8250_isa_devs);
 unreg_pnp:
@@ -355,6 +353,17 @@ static int __init serial8250_init(void)
 out:
 	return ret;
 }
+
+static int __init serial8250_init(void)
+{
+	if (ARRAY_SIZE(old_serial_port)) {
+		int ret = serial8250_isa_init();
+		if (ret)
+			return ret;
+	}
+
+	return platform_driver_register(&serial8250_platform_driver);
+}
 module_init(serial8250_init);
 
 static void __exit serial8250_exit(void)
@@ -368,7 +377,11 @@ static void __exit serial8250_exit(void)
 	 */
 	serial8250_isa_devs = NULL;
 
-	platform_driver_unregister(&serial8250_isa_driver);
+	platform_driver_unregister(&serial8250_platform_driver);
+
+	if (!ARRAY_SIZE(old_serial_port))
+		return;
+
 	platform_device_unregister(isa_dev);
 
 	serial8250_pnp_exit();

  reply	other threads:[~2024-11-22 22:54 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 15:29 [PATCH 0/1] tty: Handle " Niklas Schnelle
2024-04-05 15:29 ` [PATCH 1/1] tty: serial: handle " Niklas Schnelle
2024-04-08  9:54   ` Ilpo Järvinen
2024-04-08 10:17     ` Arnd Bergmann
2024-04-08 10:25       ` Ilpo Järvinen
2024-10-01  9:04       ` Niklas Schnelle
2024-04-08 15:35     ` Niklas Schnelle
2024-04-08 15:41       ` Ilpo Järvinen
2024-04-08 15:50         ` Arnd Bergmann
2024-05-23  2:11   ` Maciej W. Rozycki
2024-10-01 11:21     ` Niklas Schnelle
2024-10-01 15:31       ` Arnd Bergmann
2024-10-01 16:41       ` Maciej W. Rozycki
2024-10-02 12:44         ` Niklas Schnelle
2024-10-02 18:12           ` Maciej W. Rozycki
2024-10-02 22:00             ` Arnd Bergmann
2024-10-02 22:59               ` Maciej W. Rozycki
2024-10-04  6:53                 ` Arnd Bergmann
2024-10-04 16:24                   ` Maciej W. Rozycki
2024-10-04 16:57                     ` Arnd Bergmann
2024-10-04 10:09                 ` Niklas Schnelle
2024-10-04 12:48                   ` Arnd Bergmann
2024-10-04 16:03                     ` Niklas Schnelle
2024-10-04 14:44                   ` Niklas Schnelle
2024-10-04 16:34                   ` Maciej W. Rozycki
2024-11-22 15:18   ` Guenter Roeck
2024-11-22 15:35     ` Niklas Schnelle
2024-11-22 16:31       ` Arnd Bergmann
2024-11-22 17:22         ` Guenter Roeck
2024-11-22 19:24           ` Arnd Bergmann
2024-11-22 20:44             ` Guenter Roeck
2024-11-22 22:51               ` Arnd Bergmann [this message]
2024-11-23  2:14                 ` Guenter Roeck
2024-11-25  7:55             ` Andy Shevchenko
2024-11-25  9:53               ` Arnd Bergmann
2024-11-25 10:33                 ` Andy Shevchenko
2024-11-25 11:06                   ` Arnd Bergmann
2024-11-25 11:26                     ` Andy Shevchenko
2024-11-25 13:50                       ` Arnd Bergmann
2024-11-25 15:42                         ` Andy Shevchenko
2024-11-25 16:54                         ` Maciej W. Rozycki
2024-11-25 17:54                           ` Arnd Bergmann
2024-11-25 18:42                             ` Maciej W. Rozycki
2024-12-04 18:51                             ` Guenter Roeck
2024-11-25 15:59                     ` Arnd Bergmann
2024-12-04 21:09                       ` Guenter Roeck
2024-12-04 22:17                         ` Arnd Bergmann
2024-12-04 22:44                           ` Guenter Roeck
2024-12-05  7:08                             ` Arnd Bergmann
2024-12-05 14:31                               ` Guenter Roeck
2024-12-06 15:44                           ` Andy Shevchenko
2024-12-06 16:02                             ` Arnd Bergmann
2025-01-16 12:26                               ` Andy Shevchenko
2024-11-22 17:07       ` Guenter Roeck
2024-11-22 23:27         ` Niklas Schnelle
2024-11-22 23:34         ` Niklas Schnelle
2024-11-23  9:21           ` Arnd Bergmann
2024-04-05 22:33 ` [PATCH 0/1] tty: Handle " Andy Shevchenko
2024-04-06  8:06   ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb1c5d4b-0662-41dd-826c-d3c3cf78de2b@app.fastmail.com \
    --to=arnd@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hca@linux.ibm.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=schnelle@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®