[PATCH 5/7] drivers/tty/serial_core: add local variable for newly allocated attribute_group**

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux