Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1267215lqb; Thu, 30 May 2024 05:45:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXb6Qh5OLhN1GRxFlhrs4nB2dEZivZ/FTEJPKn6P0YXrB+QEm/mvHlP/5PK4IbsxJRZH1yYNB4xghtwJr1kvBvLS+hOGISbWwRmNcAGDw== X-Google-Smtp-Source: AGHT+IGvuKprjNnLCdWKKw321vb8QGFoy2gm2yvK6d/6x1wbGetdpnUormPUFmVxl6SfT41l0sKE X-Received: by 2002:a50:ab0f:0:b0:578:5eab:3f31 with SMTP id 4fb4d7f45d1cf-57a17974d3fmr2104432a12.38.1717073111296; Thu, 30 May 2024 05:45:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717073111; cv=pass; d=google.com; s=arc-20160816; b=W8L17jv0DsPwm6vN/2fGzz6hyHR3csrQTsD+vcPCF0j2KU83gsELs6UG1ehXx0Q/z6 FX/1EoV1AGQJ5ru6RJFLMavRdjIW4tsy2r8leB4O+NnyuZo938x8yF1fR0pNcatCUnH/ BBhMkEcXqJ4ybKCYGiPbiGO8PFLi+611EI2KE5ndxJYOxRShjWfpuDua3LPx7O+2aagP 2iiQjq3BWZG/QvXrUxkRymBDQZuAIX7lXfga9DmDE+oE1lO2qxNGGj/U/n9eJYqCYTxy UvHWA/ZvgLhuA/yfaxACtmFxBuq8IlvaxC7QUMWwOzWbrl5Ej2FHncqONiI6H5eNtcOn ebtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SEOD7dQKzYRkR/dORqsEkw2YEii0spJF7RUz/RjEMLo=; fh=WWSsioJahrMOOvPhDTOCtJ4iI2wkNwghMDBcUDfdxUo=; b=ipU53zi6/xHEyO2fFmJoy/Lue/uIfggMFST0wcp30V/M15zAXMeB7f/kWvWRv66wSs qH0YCtMCztLs0I6z9Gw5DKNvQZPx84c7pIvu/+MkUy1qRCSvJfaEM27V2PpOCkfrtCWN a6uK1nrv+FjzzizXpmt3rO6zJXdH79AxJxMB9ujjdaHFRU7dsYhhcfZTlfacsgCBFOvq 4YDHaX95tFjIn3wVTbn8hX1EiZmYrfeR2Rl+W6YzvLi6DsEn13AnBrZbJuSHuny/+LhK kEitGfvtkEBWY+xs8Tr8lcutsxsu7nIP+b/Ppou/6B33me9VwUwiRbJV2lZ9DFGszEu6 krNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ioZafEyQ; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-195379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a2431e547si478780a12.595.2024.05.30.05.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 05:45:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ioZafEyQ; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-195379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D58661F22BEE for ; Thu, 30 May 2024 12:45:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B4FB17F500; Thu, 30 May 2024 12:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ioZafEyQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 253CB13211A; Thu, 30 May 2024 12:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073097; cv=none; b=tkwchYTyj8vO8loxxdI7FePHWLYeNXFpOjSaJA4gkrq3Q6qYfK7EkNxiVqtEK5LcqUy1EPvpYB0giAitK1RoSDyNh5vx3NGm48updL3ZOQPgENQ+7tlXVHHGvu1tlIto1hdZ4kumO+DkWFDjLOCTYODkyC4WuPxiU7GowRjfFBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073097; c=relaxed/simple; bh=BE5vKjWoF5clRJtqrDhKP5DaIp8mpQT6m134/dlB5jY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dLgTKmEf/V9I67txFQoqLszovak8WfLjVXaHS2YMhho7cN9hh+hhYO3eZimDxuR1v6Nn3kjmORC3imd/Vc3Gtj1vimlFHyM1En1P3lqxrLouDz1IamfRTkmNWmNxxqPn0VBtAjujtj46Kd/ZlxDC5O3lfgXrYqZyWuGFG+0nQxo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ioZafEyQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 569AFC2BBFC; Thu, 30 May 2024 12:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717073096; bh=BE5vKjWoF5clRJtqrDhKP5DaIp8mpQT6m134/dlB5jY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ioZafEyQtEczCqRpQo7xFcf/W2XF5tkER2qdhpO6JVZpf6j6P0711matV43Ya70gZ ii3noAJn8+slkpAUbPSJ6+bC2bf8NVi+YUhh69hDtKPZXIbTvjAiPIB5Y1rMBsor3z Dw5U8mxIVDzJn6bxhHdCCDPTplUhcJDG60LAtP2g= Date: Thu, 30 May 2024 14:45:02 +0200 From: Greg Kroah-Hartman To: CrescentCY Hsieh Cc: Jiri Slaby , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH] tty: serial: 8250: Passing attr_group to universal driver Message-ID: <2024053013-clapping-germless-d50d@gregkh> References: <20240530094457.1974-1-crescentcy.hsieh@moxa.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240530094457.1974-1-crescentcy.hsieh@moxa.com> On Thu, May 30, 2024 at 05:44:57PM +0800, CrescentCY Hsieh wrote: > Many low-level drivers in Linux kernel register their serial ports with > the help of universal driver (8250_core, 8250_port). > > There is an attribute group called `serial8250_dev_attr_group` within > `8250_port.c` to handle the `rx_trig_bytes` attribute: > https://lore.kernel.org/all/20140716011931.31474.68825.stgit@yuno-kbuild.novalocal/ > > However, if a low-level driver has some HW specifications that need to > be set or retrieved using an attr_group, the universal driver > (8250_port) would overwrite the low-level driver's attr_group. > > This patch allows the low-level driver's attr_group to be passed to the > universal driver (8250_port) and combines the two attr_groups. This > ensures that the corresponding system file will only be created if the > device is registered by such a low-level driver. Great! But is this needed now by any in-kernel drivers, or is this only needed by things that are not in our tree? If in our tree, what driver(s) does this fix up? If none, then for obvious reasons, we can't take this change. > > Signed-off-by: CrescentCY Hsieh > --- > drivers/tty/serial/8250/8250_core.c | 9 +++++++++ > drivers/tty/serial/8250/8250_port.c | 26 ++++++++++++++++++++++++-- > include/linux/serial_core.h | 1 + > 3 files changed, 34 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c > index 43824a174a51..01d04f9d5192 100644 > --- a/drivers/tty/serial/8250/8250_core.c > +++ b/drivers/tty/serial/8250/8250_core.c > @@ -1130,6 +1130,8 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) > uart->port.pm = up->port.pm; > if (up->port.handle_break) > uart->port.handle_break = up->port.handle_break; > + if (up->port.attr_group) > + uart->port.attr_group = up->port.attr_group; > if (up->dl_read) > uart->dl_read = up->dl_read; > if (up->dl_write) > @@ -1210,6 +1212,13 @@ void serial8250_unregister_port(int line) > uart->port.type = PORT_UNKNOWN; > uart->port.dev = &serial8250_isa_devs->dev; > uart->port.port_id = line; > + > + if (uart->port.attr_group_allocated) { > + kfree(uart->port.attr_group->attrs); > + kfree(uart->port.attr_group); > + uart->port.attr_group_allocated = false; Why is this needed to be set to false now, how can it matter anymore? > + } > + uart->port.attr_group = NULL; > uart->capabilities = 0; > serial8250_init_port(uart); > serial8250_apply_quirks(uart); > diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c > index 893bc493f662..ddfa8b59e562 100644 > --- a/drivers/tty/serial/8250/8250_port.c > +++ b/drivers/tty/serial/8250/8250_port.c > @@ -3135,9 +3135,31 @@ static struct attribute_group serial8250_dev_attr_group = { > static void register_dev_spec_attr_grp(struct uart_8250_port *up) > { > const struct serial8250_config *conf_type = &uart_config[up->port.type]; > + struct attribute **upp_attrs = NULL; > + int upp_attrs_num = 0, i; > > - if (conf_type->rxtrig_bytes[0]) > - up->port.attr_group = &serial8250_dev_attr_group; > + up->port.attr_group_allocated = false; > + > + if (up->port.attr_group) { > + upp_attrs = up->port.attr_group->attrs; > + > + while (upp_attrs[upp_attrs_num]) > + upp_attrs_num++; > + > + up->port.attr_group = kcalloc(1, sizeof(struct attribute_group), GFP_KERNEL); > + up->port.attr_group->attrs = kcalloc(upp_attrs_num + 2, sizeof(struct attribute *), GFP_KERNEL); > + > + for (i = 0; i < upp_attrs_num; ++i) > + up->port.attr_group->attrs[i] = upp_attrs[i]; > + > + if (conf_type->rxtrig_bytes[0]) > + up->port.attr_group->attrs[upp_attrs_num] = &dev_attr_rx_trig_bytes.attr; > + > + up->port.attr_group_allocated = true; This feels odd, why is this all dynamically allocated? You want to add another group to the existing group? > + } else { > + if (conf_type->rxtrig_bytes[0]) > + up->port.attr_group = &serial8250_dev_attr_group; > + } > } > > static void serial8250_config_port(struct uart_port *port, int flags) > diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h > index 8cb65f50e830..3212d64c32c6 100644 > --- a/include/linux/serial_core.h > +++ b/include/linux/serial_core.h > @@ -581,6 +581,7 @@ struct uart_port { > unsigned char console_reinit; > const char *name; /* port name */ > struct attribute_group *attr_group; /* port specific attributes */ > + bool attr_group_allocated; /* whether attr_group is dynamic allocated */ Any way to do this without this variable? thanks, greg k-h