Message ID | 20230810065737.47294-1-tony@atomide.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp241265vqi; Thu, 10 Aug 2023 00:20:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVUMrS9tqfM6R53jjlgnNU7Erh2Y7DphA+81hvrNAaoMKTdeSr3bmgCo7LT09EniqGdR9t X-Received: by 2002:a54:4492:0:b0:3a3:6f20:39b4 with SMTP id v18-20020a544492000000b003a36f2039b4mr1708148oiv.29.1691652053206; Thu, 10 Aug 2023 00:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691652053; cv=none; d=google.com; s=arc-20160816; b=kTheu6r/MTnfcrIDALDBSRbBpnrSw45cPi7KyvU/4z9QK8C5fJtdYNbXaHZatBRDFg 260cJlwWBPlDxJSHxTqPpRbd8YEArcn7bIffg7pZTqvX7xAiZrun9+sfzc0q0Kv4ej84 xE7y69DS8/5Uwk/U1v2uq2DLNJOxXaZtvHssx1twnGfF/XI56YAsRXV1YhqJ6saDF6iS uNurSW1lkTqWt+UIfEOm3yfTwBWfyknqQrZeTq89AnPliS9lma9KU32bVZ67ys88ywmC +rBzHXym8kUGQm5AC0gD0qoEkR0/iCUzXHHedKtJ7Lyt1vuWgoJsAy5Fe3ObHdfS7wLj W+GQ== 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=6C7zBxH370Ej8Gf7/tltDfeuKsWgh6WFI56laOMUgrM=; fh=m/k2RZybUoLEVX0Ev44OqlFoslBjKRRAtUW0pTDUGI8=; b=SfbnZ7NvBaOXJVxQHcKrQY45EBwWrr2K/hBisNTkxhQZ2sKCh08K73U/bvDd1pGCEM LpgyhJ05ohe5E6nlKw1Uy2TDSHv3XRB3orOo9LhN3y9CRomGF0ba2m3yct8hZWYVo9lh Fs57v25dzZ2o1LQ7PEgM5c633On5mTEyZT1S1AgWzXBBcmTRLaiRvGENe/IK0zbGt0s4 szpH0hsKEhGtQv4rGjP/cYGPey5R72S7NugJDGPjL2eYUul32SiFrXzlOkeMR6HOdzAc TSg1YwN32HLW94z3TK5y2LcRDa4z2j6kOUV5sDDfJhwPcUoqDM6qqILDdQLHWoytAvgZ AaOA== 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 hs14-20020a17090b200e00b0025979e8c246si1024206pjb.70.2023.08.10.00.20.39; Thu, 10 Aug 2023 00:20:53 -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 S231991AbjHJG5v (ORCPT <rfc822;craechal@gmail.com> + 99 others); Thu, 10 Aug 2023 02:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbjHJG5t (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Aug 2023 02:57:49 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7EB1810C0; Wed, 9 Aug 2023 23:57:49 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 39DB180A9; Thu, 10 Aug 2023 06:57:47 +0000 (UTC) From: Tony Lindgren <tony@atomide.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org> Cc: Andy Shevchenko <andriy.shevchenko@intel.com>, Dhruva Gole <d-gole@ti.com>, =?utf-8?q?Ilpo_J=C3=A4rvinen?= <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: [PATCH] serial: core: Fix serial core port id, including multiport devices Date: Thu, 10 Aug 2023 09:57:34 +0300 Message-ID: <20230810065737.47294-1-tony@atomide.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773825743580287601 X-GMAIL-MSGID: 1773825743580287601 |
Series |
serial: core: Fix serial core port id, including multiport devices
|
|
Commit Message
Tony Lindgren
Aug. 10, 2023, 6:57 a.m. UTC
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 <linux@roeck-us.net> Signed-off-by: Tony Lindgren <tony@atomide.com> --- drivers/tty/serial/serial_base.h | 1 + drivers/tty/serial/serial_base_bus.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-)
Comments
On Aug 10, 2023 at 09:57:34 +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. > > Fixes: 7d695d83767c ("serial: core: Fix serial_base_match() after fixing controller port name") > Tested-by: Guenter Roeck <linux@roeck-us.net> > Signed-off-by: Tony Lindgren <tony@atomide.com> > --- Please can you provide the base commit? I am unable to cleanly apply this patch on commit: 21ef7b1e17d0 (tag: next-20230809, linux-next/master) Add linux-next specific files for 20230809 > drivers/tty/serial/serial_base.h | 1 + > drivers/tty/serial/serial_base_bus.c | 28 +++++++++++++++++++++++++++- > 2 files changed, 28 insertions(+), 1 deletion(-) > [...] > > 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; > + unsigned int min = 0, max = ~0U; > 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); > } > > -- > 2.41.0 > This is the issue I faced: ➜ patch -p1 < patches/20230810_tony_serial_core_fix_serial_core_port_id_including_multiport_devices.mbx patching file drivers/tty/serial/serial_base.h patching file drivers/tty/serial/serial_base_bus.c Hunk #3 FAILED at 145. 1 out of 4 hunks FAILED -- saving rejects to file drivers/tty/serial/serial_base_bus.c.rej Perhaps this patch needs a rebase?
* Dhruva Gole <d-gole@ti.com> [230810 08:36]: > Please can you provide the base commit? I am unable to cleanly apply > this patch on commit: 21ef7b1e17d0 (tag: next-20230809, linux-next/master) Add linux-next specific files for 20230809 This is against the current tty tree tty-linus branch, not yet in next. Regards, Tony
On Aug 10, 2023 at 09:57:34 +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. > > Fixes: 7d695d83767c ("serial: core: Fix serial_base_match() after fixing controller port name") > Tested-by: Guenter Roeck <linux@roeck-us.net> > Signed-off-by: Tony Lindgren <tony@atomide.com> > --- > 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; LGTM! Reviewed-by: Dhruva Gole <d-gole@ti.com> [...]
On Thu, Aug 10, 2023 at 09:57:34AM +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. ... > + unsigned int min = 0, max = ~0U; Shouldn't this be int? The max IIRC will be INT_MAX with this anyway.
On Thu, Aug 10, 2023 at 11:49:33AM +0300, Tony Lindgren wrote: > * Dhruva Gole <d-gole@ti.com> [230810 08:36]: > > Please can you provide the base commit? I am unable to cleanly apply > > this patch on commit: 21ef7b1e17d0 (tag: next-20230809, linux-next/master) Add linux-next specific files for 20230809 > > This is against the current tty tree tty-linus branch, not yet in next. What he is suggesting is you using --base when formatting your patch. Then you don't need to repeat this to every reviewer/tester/etc :-)
On Thu, Aug 10, 2023 at 06:24:13PM +0300, Andy Shevchenko wrote: > On Thu, Aug 10, 2023 at 09:57:34AM +0300, Tony Lindgren wrote: ... > > + unsigned int min = 0, max = ~0U; > > Shouldn't this be int? The max IIRC will be INT_MAX with this anyway. Ah, and then you can supply is as 0 (IIRC).
* Andy Shevchenko <andriy.shevchenko@intel.com> [230810 15:26]: > On Thu, Aug 10, 2023 at 06:24:13PM +0300, Andy Shevchenko wrote: > > On Thu, Aug 10, 2023 at 09:57:34AM +0300, Tony Lindgren wrote: > > ... > > > > + unsigned int min = 0, max = ~0U; > > > > Shouldn't this be int? The max IIRC will be INT_MAX with this anyway. > > Ah, and then you can supply is as 0 (IIRC). The returned id will be INT_MAX, but idr.h uses unsigned int: int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); If there's some reason to limit max id we can do it, otherwise it's just a don't care flag. Please clarify if I'm not following what you are suggesting :) Regards, Tony
On Fri, Aug 11, 2023 at 08:11:21AM +0300, Tony Lindgren wrote: > * Andy Shevchenko <andriy.shevchenko@intel.com> [230810 15:26]: > > On Thu, Aug 10, 2023 at 06:24:13PM +0300, Andy Shevchenko wrote: > > > On Thu, Aug 10, 2023 at 09:57:34AM +0300, Tony Lindgren wrote: ... > > > > + unsigned int min = 0, max = ~0U; > > > > > > Shouldn't this be int? The max IIRC will be INT_MAX with this anyway. > > > > Ah, and then you can supply is as 0 (IIRC). > > The returned id will be INT_MAX, but idr.h uses unsigned int: > > int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); > > If there's some reason to limit max id we can do it, otherwise it's just > a don't care flag. > > Please clarify if I'm not following what you are suggesting :) ... max = 0; Will have the same effect with more explicit intention "use whatever maximum is default". With ~0U I would expect to see something bigger than INT_MAX, but it won't ever appear.
On Fri, Aug 11, 2023 at 12:35:01PM +0300, Andy Shevchenko wrote: > On Fri, Aug 11, 2023 at 08:11:21AM +0300, Tony Lindgren wrote: > > * Andy Shevchenko <andriy.shevchenko@intel.com> [230810 15:26]: > > > On Thu, Aug 10, 2023 at 06:24:13PM +0300, Andy Shevchenko wrote: > > > > On Thu, Aug 10, 2023 at 09:57:34AM +0300, Tony Lindgren wrote: ... > > > > > + unsigned int min = 0, max = ~0U; > > > > > > > > Shouldn't this be int? The max IIRC will be INT_MAX with this anyway. > > > > > > Ah, and then you can supply is as 0 (IIRC). > > > > The returned id will be INT_MAX, but idr.h uses unsigned int: > > > > int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); > > > > If there's some reason to limit max id we can do it, otherwise it's just > > a don't care flag. > > > > Please clarify if I'm not following what you are suggesting :) > > ... max = 0; > > Will have the same effect with more explicit intention "use whatever maximum is > default". With ~0U I would expect to see something bigger than INT_MAX, but it > won't ever appear. You can put a comment on top /* Use 0 for max to apply IDA defaults */
On Fri, Aug 11, 2023 at 12:35:56PM +0300, Andy Shevchenko wrote: > On Fri, Aug 11, 2023 at 12:35:01PM +0300, Andy Shevchenko wrote: > > On Fri, Aug 11, 2023 at 08:11:21AM +0300, Tony Lindgren wrote: > > > * Andy Shevchenko <andriy.shevchenko@intel.com> [230810 15:26]: > > > > On Thu, Aug 10, 2023 at 06:24:13PM +0300, Andy Shevchenko wrote: > > > > > On Thu, Aug 10, 2023 at 09:57:34AM +0300, Tony Lindgren wrote: ... > > > > > > + unsigned int min = 0, max = ~0U; > > > > > > > > > > Shouldn't this be int? The max IIRC will be INT_MAX with this anyway. > > > > > > > > Ah, and then you can supply is as 0 (IIRC). > > > > > > The returned id will be INT_MAX, but idr.h uses unsigned int: > > > > > > int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); > > > > > > If there's some reason to limit max id we can do it, otherwise it's just > > > a don't care flag. > > > > > > Please clarify if I'm not following what you are suggesting :) > > > > ... max = 0; > > > > Will have the same effect with more explicit intention "use whatever maximum is > > default". With ~0U I would expect to see something bigger than INT_MAX, but it > > won't ever appear. > > You can put a comment on top > > /* Use 0 for max to apply IDA defaults */ Hmm... Looking into the implementation code it seems better to have /* Use -1 for max to apply IDA defaults */ int min = 0, max = -1; And supply like that.
* Andy Shevchenko <andriy.shevchenko@intel.com> [230811 09:40]: > Hmm... Looking into the implementation code it seems better to have > > /* Use -1 for max to apply IDA defaults */ > int min = 0, max = -1; > > And supply like that. OK let's use that, will send out v2. Thanks, Tony
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; + unsigned int min = 0, max = ~0U; 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); }