Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2793278rdb; Tue, 12 Sep 2023 12:13:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2qhX6dj9wgfb1SNHKCqHYI1jw8SKT5bnohLAKHM9+1Kv/OJ6V+pa0Jw9/R8ArtHL6hc1E X-Received: by 2002:a05:6a20:e109:b0:138:2fb8:6a14 with SMTP id kr9-20020a056a20e10900b001382fb86a14mr426367pzb.3.1694545990073; Tue, 12 Sep 2023 12:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694545990; cv=none; d=google.com; s=arc-20160816; b=E7b1YCFw42+UM7hRjoRM1AZTukZNjwgwMdz5UQkctv165pDvli1GHTy+6p/HhpH0k7 nLsewwSA8zZGML9EXVURWtPmzUV1Tc1vnoa2YX/PAVqH5qtVdP9KeL7DGKt+tRWxCF2B 6NGVRB8Squ7f6s2N4LPI8AFqSTBTQe/w1T3upO+RVwI5hvGQ4Il50qZRxgYRHFYGyAwG B6BB+RNcXtzJdkEQoUk+enxvTDCupibb/96K14+Rmma5BStlriL6wQaXBSnrZXmrCMWA n2T/+9HLYYIkU+4iFdTPxYysdoLErdR7qT1pKoTa7iYUqPT0MdFcFk7U5UyZCiolHhPG Dnpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Z8tAEl/Lux9OMYRj8QbJX4VhykkiVsA0UyjFlLQZAjs=; fh=+pEOKK4xluj0DFGnswAzUpS/5uIsoOZyK/cWca0wJEs=; b=xEvpomhb6AWSOzohzyXoqbgzuXX8/6u686y9sOGoeRd1oygQeCN9CDIb2kRFqMSci5 lSwZLaPckhHZDa5LzIcQ4ZGxkv2xHL8A0qhYDQgi205UCUTXCLmLxfgcT9vMqeVpzVEI twQkU5X8ToVQbhZl2S3uXoAKqUxzxbbDbM+HCgQwvI6a6k8Ni1Ot3HI85EWIjL+m4M/B MUY26bCjdR+tUkAaTeoDC7A56roEsb7edqXvwucwph4UlQgd2ezfrJ2L7dOR6djHx2Kx P9cC2pyiHlfws5iQ6rIdHUDf16Bq2cLghjGvAAJymsrgCdkMYtX2rGUETSUtU6ZbfMgq /GSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eA9L46RG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id p21-20020a056a000a1500b0068e4debbe12si8380971pfh.371.2023.09.12.12.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 12:13:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eA9L46RG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CF1EB822792E; Tue, 12 Sep 2023 08:08:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236194AbjILPHv (ORCPT + 99 others); Tue, 12 Sep 2023 11:07:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236351AbjILPHm (ORCPT ); Tue, 12 Sep 2023 11:07:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5721717; Tue, 12 Sep 2023 08:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694531258; x=1726067258; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=txUBt16FAPKgP2na7/yuErGVgUSLTzrXNIzLNXszvrs=; b=eA9L46RGueFHVYqcJgQPdXfYPimj2HXo6GphBANywut5u6jSs7ibwWZc l5Q+409FS1KMAGl7UDbOvxREtPS9zNCyGXXj09Hi59FHSpZ/Vh9ccBi1M 7I2Zhxy4usdqdlWdLooDprOuQzKmKBzh5myHxoqSVhImToGxMurCkjJny NgaA/K8M5pLu3z/js5hYqYClFo6iPE2tUbmTTsDjZJ2n3qsZeeIDKG2K0 8OpQW00bImM6YuymyHVPIdxyGK4LT5iiwY6M0CBBEkOIBv+5mWjR6r72c NhpbaE3XN2EO0s2gtfz0Koy4QFOsl29Kn9SYxMPs7Ya+mL+zEL6G+HcWb g==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="409356631" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="409356631" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 08:06:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="990530040" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="990530040" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 08:06:18 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qg4xz-008c3r-28; Tue, 12 Sep 2023 18:06:15 +0300 Date: Tue, 12 Sep 2023 18:06:15 +0300 From: Andy Shevchenko To: Tony Lindgren Cc: Greg Kroah-Hartman , Jiri Slaby , Dhruva Gole , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v2 2/3] serial: core: Add support for DEVNAME:0.0 style naming for kernel console Message-ID: References: <20230912110350.14482-1-tony@atomide.com> <20230912110350.14482-3-tony@atomide.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230912110350.14482-3-tony@atomide.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Sep 2023 08:08:09 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email On Tue, Sep 12, 2023 at 02:03:44PM +0300, Tony Lindgren wrote: > We can now add hardware based addressing to serial ports. Starting with > commit 84a9582fd203 ("serial: core: Start managing serial controllers to > enable runtime PM"), and all the related fixes to this commit, the serial > core now knows to which serial port controller the ports are connected. > > The serial ports can be addressed with DEVNAME:0.0 style naming. The names > are something like 00:04:0.0 for a serial port on qemu, and something like > 2800000.serial:0.0 on platform device using systems like ARM64 for example. > > The DEVNAME is the unique serial port hardware controller device name, AKA > the name for port->dev. The 0.0 are the serial core controller id and port > id. > > Typically 0.0 are used for each controller and port instance unless the > serial port hardware controller has multiple controllers or ports. > > Using DEVNAME:0.0 style naming actually solves two long term issues for > addressing the serial ports: > > 1. According to Andy Shevchenko, using DEVNAME:0.0 style naming fixes an > issue where depending on the BIOS settings, the kernel serial port ttyS > instance number may change if HSUART is enabled > > 2. Device tree using architectures no longer necessarily need to specify > aliases to find a specific serial port, and we can just allocate the > ttyS instance numbers dynamically in whatever probe order > > To do this, we need a custom init time parser for the console= command > line option as printk already handles parsing it with console_setup(). > Also early_param() gets handled by console_setup() if "console" and > "earlycon" are used. ... > +#ifdef CONFIG_SERIAL_CORE_CONSOLE > +int serial_base_add_preferred_console(struct uart_driver *drv, > + struct uart_port *port); > +#else > +static inline int serial_base_add_preferred_console(struct uart_driver *drv, > + struct uart_port *port) Maybe static inline int serial_base_add_preferred_console(struct uart_driver *drv, struct uart_port *port) for being aligned with the above? > +{ > + return 0; > +} > +#endif ... > +#include > +#include > +#include Hmm... Can we use better header(s) instead? types.h, etc? > +#include > +#include ... > +static LIST_HEAD(serial_base_consoles); Don't you need a locking to access this list? If not, perhaps a comment why it's okay? ... > +int serial_base_add_preferred_console(struct uart_driver *drv, > + struct uart_port *port) > +{ > + struct serial_base_console *entry; > + char *port_match; ... > + port_match = kasprintf(GFP_KERNEL, "%s:%i.%i", dev_name(port->dev), > + port->ctrl_id, port->port_id); What about starting using cleanup.h? > + if (!port_match) > + return -ENOMEM; > + > + list_for_each_entry(entry, &serial_base_consoles, node) { > + if (!strcmp(port_match, entry->name)) { > + add_preferred_console(drv->dev_name, port->line, > + entry->opt); > + break; > + } > + } > + > + kfree(port_match); Also (with the above) this can be written as list_for_each_entry(entry, &serial_base_consoles, node) { if (!strcmp(port_match, entry->name)) break; } if (list_entry_is_head(entry, &serial_base_consoles, node) return 0; // Hmm... it maybe -ENOENT, but okay. add_preferred_console(drv->dev_name, port->line, entry->opt); > + return 0; > +} ... > +EXPORT_SYMBOL_GPL(serial_base_add_preferred_console); Can we use (start using) namespaced exports? ... > +static int __init serial_base_add_con(char *name, char *opt) const name const opt ? > +{ > + struct serial_base_console *con; > + > + con = kzalloc(sizeof(*con), GFP_KERNEL); > + if (!con) > + return -ENOMEM; > + > + con->name = kstrdup(name, GFP_KERNEL); > + if (!con->name) > + goto free_con; > + > + if (opt) { > + con->opt = kstrdup(opt, GFP_KERNEL); > + if (!con->name) Are you sure? I think it's c&p typo here. > + goto free_name; > + } > + > + list_add_tail(&con->node, &serial_base_consoles); > + > + return 0; > + > +free_name: > + kfree(con->name); > + > +free_con: > + kfree(con); With cleanup.h this will look much better. > + return -ENOMEM; > +} ... > +static int __init serial_base_parse_one(char *param, char *val, > + const char *unused, void *arg) > +{ > + char *opt; > + > + if (strcmp(param, "console")) > + return 0; > + > + if (!val) > + return 0; > + opt = strchr(val, ','); > + if (opt) { > + opt[0] = '\0'; > + opt++; > + } strsep() ? Actually param_array() uses strcspn() in similar situation. > + if (!strlen(val)) > + return 0; Btw, have you seen lib/cmdline.c? Can it be helpful here? > + return serial_base_add_con(val, opt); > +} -- With Best Regards, Andy Shevchenko