Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: sc16is7xx: simplify to_sc16is7xx_one() with a single parameter

Simplify macro to_sc16is7xx_one() to only take one parameter, as most
of the time (19) it is called with the "port" structure name. This
improves readability.

For the remaining places where it is called (4), simply use container_of()
locally. This is similar to what is done in other drivers (ex: max310x).
For sc16is7xx_tx_proc(), first assigning "one" variable allows to simplify
"port" variable init.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://patch.msgid.link/20251027142957.1032073-10-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hugo Villeneuve and committed by
Greg Kroah-Hartman
e92f83af a5bb1465

+24 -24
+24 -24
drivers/tty/serial/sc16is7xx.c
··· 366 366 .nr = SC16IS7XX_MAX_DEVS, 367 367 }; 368 368 369 - #define to_sc16is7xx_one(p,e) ((container_of((p), struct sc16is7xx_one, e))) 369 + #define to_sc16is7xx_one(p) container_of((p), struct sc16is7xx_one, port) 370 370 371 371 static u8 sc16is7xx_port_read(struct uart_port *port, u8 reg) 372 372 { 373 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 373 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 374 374 unsigned int val = 0; 375 375 376 376 regmap_read(one->regmap, reg, &val); ··· 380 380 381 381 static void sc16is7xx_port_write(struct uart_port *port, u8 reg, u8 val) 382 382 { 383 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 383 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 384 384 385 385 regmap_write(one->regmap, reg, val); 386 386 } 387 387 388 388 static void sc16is7xx_fifo_read(struct uart_port *port, u8 *rxbuf, unsigned int rxlen) 389 389 { 390 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 390 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 391 391 392 392 regmap_noinc_read(one->regmap, SC16IS7XX_RHR_REG, rxbuf, rxlen); 393 393 } 394 394 395 395 static void sc16is7xx_fifo_write(struct uart_port *port, u8 *txbuf, u8 to_send) 396 396 { 397 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 397 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 398 398 399 399 /* 400 400 * Don't send zero-length data, at least on SPI it confuses the chip ··· 409 409 static void sc16is7xx_port_update(struct uart_port *port, u8 reg, 410 410 u8 mask, u8 val) 411 411 { 412 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 412 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 413 413 414 414 regmap_update_bits(one->regmap, reg, mask, val); 415 415 } ··· 441 441 */ 442 442 static void sc16is7xx_regs_lock(struct uart_port *port, u8 register_set) 443 443 { 444 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 444 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 445 445 446 446 mutex_lock(&one->lock); 447 447 ··· 457 457 458 458 static void sc16is7xx_regs_unlock(struct uart_port *port) 459 459 { 460 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 460 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 461 461 462 462 /* Re-enable cache updates when writing to general registers */ 463 463 regcache_cache_bypass(one->regmap, false); ··· 471 471 static void sc16is7xx_ier_clear(struct uart_port *port, u8 bit) 472 472 { 473 473 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 474 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 474 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 475 475 476 476 lockdep_assert_held_once(&port->lock); 477 477 ··· 484 484 static void sc16is7xx_ier_set(struct uart_port *port, u8 bit) 485 485 { 486 486 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 487 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 487 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 488 488 489 489 lockdep_assert_held_once(&port->lock); 490 490 ··· 615 615 static void sc16is7xx_handle_rx(struct uart_port *port, unsigned int rxlen, 616 616 unsigned int iir) 617 617 { 618 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 618 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 619 619 unsigned int lsr = 0, bytes_read, i; 620 620 bool read_lsr = (iir == SC16IS7XX_IIR_RLSE_SRC); 621 621 u8 ch, flag; ··· 782 782 { 783 783 unsigned int iir, rxlen; 784 784 struct uart_port *port = &s->p[portno].port; 785 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 785 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 786 786 787 787 guard(mutex)(&one->lock); 788 788 ··· 862 862 863 863 static void sc16is7xx_tx_proc(struct kthread_work *ws) 864 864 { 865 - struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port); 866 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 865 + struct sc16is7xx_one *one = container_of(ws, struct sc16is7xx_one, tx_work); 866 + struct uart_port *port = &one->port; 867 867 868 868 if ((port->rs485.flags & SER_RS485_ENABLED) && 869 869 (port->rs485.delay_rts_before_send > 0)) ··· 895 895 896 896 static void sc16is7xx_reg_proc(struct kthread_work *ws) 897 897 { 898 - struct sc16is7xx_one *one = to_sc16is7xx_one(ws, reg_work); 898 + struct sc16is7xx_one *one = container_of(ws, struct sc16is7xx_one, reg_work); 899 899 struct sc16is7xx_one_config config; 900 900 unsigned long irqflags; 901 901 ··· 933 933 934 934 static void sc16is7xx_ms_proc(struct kthread_work *ws) 935 935 { 936 - struct sc16is7xx_one *one = to_sc16is7xx_one(ws, ms_work.work); 936 + struct sc16is7xx_one *one = container_of(ws, struct sc16is7xx_one, ms_work.work); 937 937 struct sc16is7xx_port *s = dev_get_drvdata(one->port.dev); 938 938 939 939 if (one->port.state) { ··· 946 946 947 947 static void sc16is7xx_enable_ms(struct uart_port *port) 948 948 { 949 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 949 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 950 950 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 951 951 952 952 lockdep_assert_held_once(&port->lock); ··· 957 957 static void sc16is7xx_start_tx(struct uart_port *port) 958 958 { 959 959 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 960 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 960 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 961 961 962 962 kthread_queue_work(&s->kworker, &one->tx_work); 963 963 } ··· 996 996 997 997 static unsigned int sc16is7xx_get_mctrl(struct uart_port *port) 998 998 { 999 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 999 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 1000 1000 1001 1001 /* Called with port lock taken so we can only return cached value */ 1002 1002 return one->old_mctrl; ··· 1005 1005 static void sc16is7xx_set_mctrl(struct uart_port *port, unsigned int mctrl) 1006 1006 { 1007 1007 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 1008 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 1008 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 1009 1009 1010 1010 one->config.flags |= SC16IS7XX_RECONF_MD; 1011 1011 kthread_queue_work(&s->kworker, &one->reg_work); ··· 1022 1022 struct ktermios *termios, 1023 1023 const struct ktermios *old) 1024 1024 { 1025 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 1025 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 1026 1026 unsigned int lcr, flow = 0; 1027 1027 int baud; 1028 1028 unsigned long flags; ··· 1125 1125 struct serial_rs485 *rs485) 1126 1126 { 1127 1127 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 1128 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 1128 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 1129 1129 1130 1130 if (rs485->flags & SER_RS485_ENABLED) { 1131 1131 /* ··· 1145 1145 1146 1146 static int sc16is7xx_startup(struct uart_port *port) 1147 1147 { 1148 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 1148 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 1149 1149 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 1150 1150 unsigned int val; 1151 1151 unsigned long flags; ··· 1209 1209 static void sc16is7xx_shutdown(struct uart_port *port) 1210 1210 { 1211 1211 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); 1212 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 1212 + struct sc16is7xx_one *one = to_sc16is7xx_one(port); 1213 1213 1214 1214 kthread_cancel_delayed_work_sync(&one->ms_work); 1215 1215