linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Max Kellermann <max.kellermann@ionos.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Cc: Max Kellermann <max.kellermann@ionos.com>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [PATCH 5/7] drivers/tty/serial_core: add local variable for newly allocated attribute_group**
Date: Mon,  9 Oct 2023 18:57:38 +0200	[thread overview]
Message-ID: <20231009165741.746184-5-max.kellermann@ionos.com> (raw)
In-Reply-To: <20231009165741.746184-1-max.kellermann@ionos.com>

This allows the compiler to keep the pointer in a register and
prepares for making the struct field "const".

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 drivers/tty/serial/serial_core.c | 11 ++++++-----
 include/linux/serial_core.h      |  4 ++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 7bdc21d5e13b..e253ef474fb4 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3082,6 +3082,7 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
 	struct uart_state *state;
 	struct tty_port *port;
 	int ret = 0;
+	const struct attribute_group **tty_groups;
 	struct device *tty_dev;
 	int num_groups;
 
@@ -3132,22 +3133,22 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
 	if (uport->attr_group)
 		num_groups++;
 
-	uport->tty_groups = kcalloc(num_groups, sizeof(*uport->tty_groups),
+	uport->tty_groups = tty_groups = kcalloc(num_groups, sizeof(*tty_groups),
 				    GFP_KERNEL);
-	if (!uport->tty_groups) {
+	if (!tty_groups) {
 		ret = -ENOMEM;
 		goto out;
 	}
-	uport->tty_groups[0] = &tty_dev_attr_group;
+	tty_groups[0] = &tty_dev_attr_group;
 	if (uport->attr_group)
-		uport->tty_groups[1] = uport->attr_group;
+		tty_groups[1] = uport->attr_group;
 
 	/*
 	 * Register the port whether it's detected or not.  This allows
 	 * setserial to be used to alter this port's parameters.
 	 */
 	tty_dev = tty_port_register_device_attr_serdev(port, drv->tty_driver,
-			uport->line, uport->dev, port, uport->tty_groups);
+			uport->line, uport->dev, port, tty_groups);
 	if (!IS_ERR(tty_dev)) {
 		device_set_wakeup_capable(tty_dev, 1);
 	} else {
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index bb6f073bc159..597de109dbf5 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -578,8 +578,8 @@ struct uart_port {
 	unsigned char		suspended;
 	unsigned char		console_reinit;
 	const char		*name;			/* port name */
-	struct attribute_group	*attr_group;		/* port specific attributes */
-	const struct attribute_group **tty_groups;	/* all attributes (serial core use only) */
+	const struct attribute_group *attr_group;	/* port specific attributes */
+	const struct attribute_group *const*tty_groups;	/* all attributes (serial core use only) */
 	struct serial_rs485     rs485;
 	struct serial_rs485	rs485_supported;	/* Supported mask for serial_rs485 */
 	struct gpio_desc	*rs485_term_gpio;	/* enable RS485 bus termination */
-- 
2.39.2


       reply	other threads:[~2023-10-09 16:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20231009165741.746184-1-max.kellermann@ionos.com>
2023-10-09 16:57 ` Max Kellermann [this message]
2023-10-09 17:28   ` [PATCH 5/7] drivers/tty/serial_core: add local variable for newly allocated attribute_group** Greg Kroah-Hartman
2023-10-09 16:57 ` [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const Max Kellermann
2023-10-09 17:24   ` Guenter Roeck
2023-10-09 20:05     ` Max Kellermann
2023-10-10  5:59       ` Greg Kroah-Hartman
2023-10-10  6:48       ` Joe Perches
2023-10-10  6:57         ` Greg Kroah-Hartman
2023-10-09 17:25   ` Greg Kroah-Hartman
2023-10-09 17:30     ` Max Kellermann
2023-10-09 17:31     ` Greg Kroah-Hartman
2023-10-09 20:20     ` Max Kellermann
2023-10-09 16:57 ` [PATCH 7/7] block, drivers: make lots of attribute_group globals const Max Kellermann
2023-10-09 17:30   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231009165741.746184-5-max.kellermann@ionos.com \
    --to=max.kellermann@ionos.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).