From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Tony Lindgren <tony@atomide.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Dhruva Gole" <d-gole@ti.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"John Ogness" <john.ogness@linutronix.de>,
"Johan Hovold" <johan@kernel.org>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
"Guenter Roeck" <linux@roeck-us.net>
Subject: Re: [PATCH v2 1/1] serial: core: Fix serial core port id, including multiport devices
Date: Fri, 11 Aug 2023 16:34:23 +0300 [thread overview]
Message-ID: <ZNY431TgMElF35UC@smile.fi.intel.com> (raw)
In-Reply-To: <20230811103648.2826-1-tony@atomide.com>
On Fri, Aug 11, 2023 at 01:36:45PM +0300, Tony Lindgren wrote:
> We want to fix the serial core port DEVNAME to use a port id of the
> hardware specific controller port instance instead of the port->line.
>
> For example, the 8250 driver sets up a number of serial8250 ports
> initially that can be inherited by the hardware specific driver. At that
> the port->line no longer decribes the port's relation to the serial core
> controller instance.
>
> Let's fix the issue by assigning port->port_id for each serial core
> controller port instance.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Fixes: 7d695d83767c ("serial: core: Fix serial_base_match() after fixing controller port name")
> Tested-by: Guenter Roeck <linux@roeck-us.net>
> Reviewed-by: Dhruva Gole <d-gole@ti.com>
> Signed-off-by: Tony Lindgren <tony@atomide.com>
> ---
>
> Changes since v1:
> - Generated with --base as suggested by Andy, this is against tty-linus
>
> - Initialized ida_alloc_range() values as suggested by Andy
>
> - Added Reviewed-by from Dhruva
>
> - Kept Guenter's Tested-by
>
> ---
> drivers/tty/serial/serial_base.h | 1 +
> drivers/tty/serial/serial_base_bus.c | 28 +++++++++++++++++++++++++++-
> 2 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/serial_base.h b/drivers/tty/serial/serial_base.h
> --- a/drivers/tty/serial/serial_base.h
> +++ b/drivers/tty/serial/serial_base.h
> @@ -16,6 +16,7 @@ struct device;
>
> struct serial_ctrl_device {
> struct device dev;
> + struct ida port_ida;
> };
>
> struct serial_port_device {
> diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c
> --- a/drivers/tty/serial/serial_base_bus.c
> +++ b/drivers/tty/serial/serial_base_bus.c
> @@ -10,6 +10,7 @@
>
> #include <linux/container_of.h>
> #include <linux/device.h>
> +#include <linux/idr.h>
> #include <linux/module.h>
> #include <linux/serial_core.h>
> #include <linux/slab.h>
> @@ -112,6 +113,8 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
> if (!ctrl_dev)
> return ERR_PTR(-ENOMEM);
>
> + ida_init(&ctrl_dev->port_ida);
> +
> err = serial_base_device_init(port, &ctrl_dev->dev,
> parent, &serial_ctrl_type,
> serial_base_ctrl_release,
> @@ -142,16 +145,31 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
> struct serial_ctrl_device *ctrl_dev)
> {
> struct serial_port_device *port_dev;
> + int min = 0, max = -1; /* Use -1 for max to apply IDA defaults */
> int err;
>
> port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
> if (!port_dev)
> return ERR_PTR(-ENOMEM);
>
> + /* Device driver specified port_id vs automatic assignment? */
> + if (port->port_id) {
> + min = port->port_id;
> + max = port->port_id;
> + }
> +
> + err = ida_alloc_range(&ctrl_dev->port_ida, min, max, GFP_KERNEL);
> + if (err < 0) {
> + kfree(port_dev);
> + return ERR_PTR(err);
> + }
> +
> + port->port_id = err;
> +
> err = serial_base_device_init(port, &port_dev->dev,
> &ctrl_dev->dev, &serial_port_type,
> serial_base_port_release,
> - port->ctrl_id, port->line);
> + port->ctrl_id, port->port_id);
> if (err)
> goto err_put_device;
>
> @@ -165,16 +183,24 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
>
> err_put_device:
> put_device(&port_dev->dev);
> + ida_free(&ctrl_dev->port_ida, port->port_id);
>
> return ERR_PTR(err);
> }
>
> void serial_base_port_device_remove(struct serial_port_device *port_dev)
> {
> + struct serial_ctrl_device *ctrl_dev;
> + struct device *parent;
> +
> if (!port_dev)
> return;
>
> + parent = port_dev->dev.parent;
> + ctrl_dev = to_serial_base_ctrl_device(parent);
> +
> device_del(&port_dev->dev);
> + ida_free(&ctrl_dev->port_ida, port_dev->port->port_id);
> put_device(&port_dev->dev);
> }
>
>
> base-commit: a4a79e03bab57729bd8046d22bf3666912e586fb
> --
> 2.41.0
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2023-08-11 13:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 10:36 [PATCH v2 1/1] serial: core: Fix serial core port id, including multiport devices Tony Lindgren
2023-08-11 13:34 ` Andy Shevchenko [this message]
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=ZNY431TgMElF35UC@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bigeasy@linutronix.de \
--cc=d-gole@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=johan@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=tony@atomide.com \
--cc=vigneshr@ti.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