Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp349589lqh; Fri, 31 May 2024 03:20:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6pnXoFtxiUVa3Ih+SHFV5OxKlIBK4tNpdwPSXhve+nCX79zYhlcBdv938IpqBzrKpsZDZMgHzcS/1oGZwX+J2WF5FadlH106ZF5vYfA== X-Google-Smtp-Source: AGHT+IFCJwmU1O9mHd6gxrui271k2xi9SCgOHI70KZVFf0D3UWUT3qUwKC7PIfF0JdhCVIjdGAGs X-Received: by 2002:a50:d657:0:b0:57a:33a5:9b78 with SMTP id 4fb4d7f45d1cf-57a364496famr963947a12.34.1717150825467; Fri, 31 May 2024 03:20:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717150825; cv=pass; d=google.com; s=arc-20160816; b=zznTgd/tik2RXrVX3jpKCiNL9SNgogWUB4OhSH8KSg9vAewpU0jdflIRUYoaffWcEp hkWDBiVCxmbDbr+K++cJh8pluOeZr2YA4xwCbxFhJUzoj8gpbXM28U+IaqUeVows7qZJ AYa47tuS6SGfX4DK3PJLcsYxprHbGWjOt4y8gmxFI3BA/08OI/toQbsufRpWwbQGro04 kg48ucs9gx2YNac7G2t9rUD5W9Hv91c1s+APi6aGYplwuW8Hilksvm8LH63mJOLy4FVD DqWESwuSjAqTLU2znBAMa4H9Oydra9D9WoyOke5jR7LXfDUYcKPx/8DeObg9WPiGjjLR 6tGg== 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=DXr0ZZP5l9z4dbOJEBAM8PkvoPY+cAFq23jgAE6FGe4=; fh=N3XrWI8FGPZ1oyn2NirsQ7Y4cPzZzZtGDDjMl9sGykA=; b=T7Yqvi+Yx0cK2iFUpyBm6MGqbapuhK71JleqGZXyEZ7Fb2ElpFMxskxaxVWf6tcda2 FpD6BZf8NDwgSmPj5lF0pn4BfKDEmkrxk9h2SBgl9EDNSXvsZXZEkH6ALYPLE5PJAkQJ lbleptIndWZz0sQGHpk2hf8hqAaJQHs62YtRchiol/or8vW4dAnqQ6M5QjMom1JfTQqk pKiU3Q0zSZ6y243VvV2Vw2iG/jTznYrelVTJwzTCr45Nwrt8NZN3HsrFdFfS7/ND2G6F z7BfWCuSQX5F8/EP3hZ4YqCpsqupnnAN/Op9elyCEe8G/2DmsasGIadvGlcneQWt6R0k fD+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pbkpsz6+; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-196661-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196661-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-57a31ca5c1dsi792428a12.534.2024.05.31.03.20.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 03:20:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196661-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=Pbkpsz6+; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-196661-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196661-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 326D31F24668 for ; Fri, 31 May 2024 10:20:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E74E1514D1; Fri, 31 May 2024 10:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Pbkpsz6+" 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 3A56115098C; Fri, 31 May 2024 10:20:16 +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=1717150817; cv=none; b=Q3LHuBCOGUtkkcgZPIh9JSJ3qwGPgMFmTcK28iYGdnoPPCMn4dFlnSLi0Jun+W05H9JaB0AaA2S7aHO+rgRiLS7azFMDRLS8js8B//pDCZewPUXxid3Hhey7uyhlDGGJICddPHfy+EU6K5c08FDUI+ywKvSh4EQH+l1lwNwPROk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717150817; c=relaxed/simple; bh=Afg/BlhPvdSwFvJIkGAy0jB6SLKbdIicJ+mDUKhcUZE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N1uhegJMQac4PfJZ4mRTymPi8otifvoaDnihCFaVRSiQk3KXwTWDFUBKobLoYzZ7emzgtOyxOdpMCKswHztHtqFRcCpUHCx4ZwOZfugbIm9EzkaWEoT7mxRsntC8USDWr3eDv+mmKqRl3tIcoXA/er2MI7bB3/qphHpGX96sDks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Pbkpsz6+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A45FC116B1; Fri, 31 May 2024 10:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717150816; bh=Afg/BlhPvdSwFvJIkGAy0jB6SLKbdIicJ+mDUKhcUZE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pbkpsz6+RCa6ou+xQVlEVSG9k91genUwaUZzEHbczs0OubFSPXsT+YPRRtOencDdw SQCtkV6GIOTiabdn7N9aNU9dE0xHbzklbnPiNzkOaOblZWKVVXnaR7jGxwa7EKL7iR Fc49cUza/3xp4R0bs+0AVxMFpB5IAm55b3Uk2Qk0= Date: Fri, 31 May 2024 12:20:22 +0200 From: Greg Kroah-Hartman To: Crescent CY 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: <2024053105-stony-surreal-5e0a@gregkh> References: <20240530094457.1974-1-crescentcy.hsieh@moxa.com> <2024053013-clapping-germless-d50d@gregkh> 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: On Fri, May 31, 2024 at 04:58:29PM +0800, Crescent CY Hsieh wrote: > On Thu, May 30, 2024 at 02:45:02PM +0200, Greg Kroah-Hartman wrote: > > 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. > > Currently, no in-kernel drivers utilize this, but I can add a patch in > v2 to demonstrate how this patch would work. It would be a requirement if this is to even be considered, you know that, why submit this without that? But step back, why would we want a serial port driver to have the ability to have different attributes than the normal ones? What attribute would it want to have at this layer that would be unique to the driver that is controlling it? That is almost never a good idea, it only can cause confusion and complex userspace issues when a device type can have different types of attributes just because of something "below" it controlling it. So in this case, why not create a proper child device of it's own specific type with those unique attributes instead? > > > 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? > > Yes, this approach aims to add the `attr_group` which declared in the > low-level driver to the existing one in universal driver (8250_port.c), > so that it will have the attributes from both low-level and universal > drivers. This ensures that other device nodes utilizing the universal > driver will not create the unsupported system file(s). What files would be "unsupported" here? I think we need a real example to understand what you are attempting to do here. serial ports should usually never have unique sysfs files as the serial core code should all control them properly and provide the needed interfaces to the device. If not, then why not add it to the generic serial port type so that all can use them? thanks, greg k-h