All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Tony Lindgren <tony.lindgren@linux.intel.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"John Ogness" <john.ogness@linutronix.de>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Tony Lindgren" <tony@atomide.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/4] serial: core: Add serial_base_match_and_update_preferred_console()
Date: Fri, 21 Jun 2024 14:37:27 +0200	[thread overview]
Message-ID: <ZnV0B4wakVehASn4@pathway.suse.cz> (raw)
In-Reply-To: <20240620124541.164931-5-tony.lindgren@linux.intel.com>

On Thu 2024-06-20 15:45:29, Tony Lindgren wrote:
> Let's add serial_base_match_and_update_preferred_console() for consoles
> using DEVNAME:0.0 style naming.
> 
> The earlier approach to add it caused issues in the kernel command line
> ordering as we were calling __add_preferred_console() again for the
> deferred consoles.
> 
> Signed-off-by: Tony Lindgren <tony.lindgren@linux.intel.com>

Looks good and seems to work well:

Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>

See an idea below.

> --- a/drivers/tty/serial/serial_base_bus.c
> +++ b/drivers/tty/serial/serial_base_bus.c
> @@ -204,6 +205,42 @@ void serial_base_port_device_remove(struct serial_port_device *port_dev)
>  	put_device(&port_dev->dev);
>  }
>  
> +#ifdef CONFIG_SERIAL_CORE_CONSOLE
> +
> +/**
> + * serial_base_match_and_update_preferred_console - Match and update a preferred console
> + * @drv: Serial port device driver
> + * @port: Serial port instance
> + *
> + * Tries to match and update the preferred console for a serial port for
> + * the kernel command line option console=DEVNAME:0.0.
> + *
> + * Cannot be called early for ISA ports, depends on struct device.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
> +						   struct uart_port *port)
> +{
> +	const char *port_match __free(kfree) = NULL;
> +	int ret;
> +
> +	port_match = kasprintf(GFP_KERNEL, "%s:%d.%d", dev_name(port->dev),
> +			       port->ctrl_id, port->port_id);
> +	if (!port_match)
> +		return -ENOMEM;

The name is going to be compared with:

struct console_cmdline
{
[...]
	char	devname[32];			/* DEVNAME:0.0 style device name */

It looks like an overkill to allocate such a small buffer. It would
be perfectly fine to use a buffer on stack.

Well, we would need to define somewhere (likely in include/linux/console.h):

#define CONSOLE_DEVNAME_LEN 32

and then do

	char port_match[CONSOLE_DEVNAME_LEN];
	int len;

	len = snprintf(port_match, ARRAY_SIZE(port_match), "%s:%d.%d",
		       dev_name(port->dev), port->ctrl_id, port->port_id);
	if (len >= ARRAY_SIZE(port_match)) {
		pr_warn("Console devname does not fit into the buffer: "%s:%d.%d\n",
			 dev_name(port->dev), port->ctrl_id, port->port_id);
		return -ENOMEM;
	}

The advantage is that it would warn when there are longer device names.
It would help to catch situations when CONSOLE_DEVNAME_LEN is not big enough.

It might be done in a separate patch.

> +
> +	ret = match_devname_and_update_preferred_console(port_match,
> +							 drv->dev_name,
> +							 port->line);
> +	if (ret == -ENOENT)
> +		return 0;
> +
> +	return ret;
> +}
> +
> +#endif
> +
>  static int serial_base_init(void)
>  {
>  	int ret;

Best Regards,
Petr

  reply	other threads:[~2024-06-21 12:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 12:45 [PATCH v4 0/4] Fixes for console command line ordering Tony Lindgren
2024-06-20 12:45 ` [PATCH v4 1/4] printk: Revert add_preferred_console_match() related commits Tony Lindgren
2024-06-20 12:45 ` [PATCH v4 2/4] printk: Add match_devname_and_update_preferred_console() Tony Lindgren
2024-06-20 12:45 ` [PATCH v4 3/4] serial: core: Revert unusable console quirk handling Tony Lindgren
2024-06-21 12:15   ` Petr Mladek
2024-06-20 12:45 ` [PATCH v4 4/4] serial: core: Add serial_base_match_and_update_preferred_console() Tony Lindgren
2024-06-21 12:37   ` Petr Mladek [this message]
2024-06-24  7:21     ` Tony Lindgren
2024-06-21 14:44 ` [PATCH v4 0/4] Fixes for console command line ordering Petr Mladek
2024-06-24 13:35   ` Greg Kroah-Hartman
2024-06-25  5:12     ` Tony Lindgren
2024-06-25  6:20       ` Greg Kroah-Hartman
2024-06-25  8:36         ` Petr Mladek
2024-06-25  9:07           ` Tony Lindgren

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=ZnV0B4wakVehASn4@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tony.lindgren@linux.intel.com \
    --cc=tony@atomide.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 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.