From patchwork Fri Aug 11 10:36:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 134440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1031874vqi; Fri, 11 Aug 2023 04:57:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2cdkDS6pwApDbIdvQWdDYRbkQL6/BWOtsKi6aKIIEsDxZ2lFHWYZy3yShlUwtyoiwh7mF X-Received: by 2002:a17:90b:109:b0:269:3e6b:26e3 with SMTP id p9-20020a17090b010900b002693e6b26e3mr917357pjz.33.1691755020587; Fri, 11 Aug 2023 04:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691755020; cv=none; d=google.com; s=arc-20160816; b=fkpAOAZwhq/vUxp4VT11ttBpkKmjQ7gkCSByhM5hWLwhlebFGIDM2pyzY6H/jMW6pK /TocMFCKMdAvAYqJaADJf2HmH/CuRQXUVuetfrEplCkBmncLJrsEjccRUMLjzrcyiiNH Di2zcsK2sSu5/xmhg4xx+3+fXqCopPLiHcdpUq0IROtbdBStITsAvrt5O7yLMH32evn2 q1lf6zkYR2YDw73LOLm13qx5B2rxFf6FU4l3bWnHZS1d+DA1ezyYRejRwUU8WhyxPdiu E7ln0fq10nVO2l3mkwT0zyBtlRl0JeDn7EtCKLt0Sf+uy4NrtCjE7fn6haEeowRDfHFu ozrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=DlUKPigpZ4r2EtovRMVTsUapH7sXU8Vk4vqZWnWUulc=; fh=m/k2RZybUoLEVX0Ev44OqlFoslBjKRRAtUW0pTDUGI8=; b=dQpNoCrflDiW+oXlg0Q2NmAG8+3+esT59pSjsKWgcG528Vc9bN97QssWTr78/h922R lGB0vVYa2rWSwgojd6IXseYG/Adc6KUGCpenvJ4nYATBjmsFdT2PBLl82aqtiYJyXqUc aK7XmcjOFkBuYD6ZJMBGwseS1+pt37omOjse0NPclNwk6qnFaIxxW2kDs4yLXElOgmf5 RADFKSDBx4Wny31zfMkI2EvzrpDYhhjBSTkomQLrKtP4rsTttH/FD0l/Te3HzEODqB16 8nTR2jcHw+cAhMB5Ef+xgU0jGG1QmliskI9pHjCl+jR9DPbcPm2JweV+abj9ZDm80GSc xjyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e15-20020a17090a9a8f00b0024753ec4dccsi3243831pjp.124.2023.08.11.04.56.47; Fri, 11 Aug 2023 04:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234623AbjHKKg7 (ORCPT + 99 others); Fri, 11 Aug 2023 06:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232383AbjHKKg4 (ORCPT ); Fri, 11 Aug 2023 06:36:56 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5F021C5; Fri, 11 Aug 2023 03:36:55 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 1A84280F1; Fri, 11 Aug 2023 10:36:52 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Guenter Roeck Subject: [PATCH v2 1/1] serial: core: Fix serial core port id, including multiport devices Date: Fri, 11 Aug 2023 13:36:45 +0300 Message-ID: <20230811103648.2826-1-tony@atomide.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773933712654964723 X-GMAIL-MSGID: 1773933712654964723 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. Fixes: 7d695d83767c ("serial: core: Fix serial_base_match() after fixing controller port name") Tested-by: Guenter Roeck Reviewed-by: Dhruva Gole Signed-off-by: Tony Lindgren Reviewed-by: Andy Shevchenko --- 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(-) base-commit: a4a79e03bab57729bd8046d22bf3666912e586fb 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 #include +#include #include #include #include @@ -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); }