Skip to content

Commit e92f83a

Browse files
hvilleneuvedoogregkh
authored andcommitted
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>
1 parent a5bb146 commit e92f83a

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

drivers/tty/serial/sc16is7xx.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ static struct uart_driver sc16is7xx_uart = {
366366
.nr = SC16IS7XX_MAX_DEVS,
367367
};
368368

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)
370370

371371
static u8 sc16is7xx_port_read(struct uart_port *port, u8 reg)
372372
{
373-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
373+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
374374
unsigned int val = 0;
375375

376376
regmap_read(one->regmap, reg, &val);
@@ -380,21 +380,21 @@ static u8 sc16is7xx_port_read(struct uart_port *port, u8 reg)
380380

381381
static void sc16is7xx_port_write(struct uart_port *port, u8 reg, u8 val)
382382
{
383-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
383+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
384384

385385
regmap_write(one->regmap, reg, val);
386386
}
387387

388388
static void sc16is7xx_fifo_read(struct uart_port *port, u8 *rxbuf, unsigned int rxlen)
389389
{
390-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
390+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
391391

392392
regmap_noinc_read(one->regmap, SC16IS7XX_RHR_REG, rxbuf, rxlen);
393393
}
394394

395395
static void sc16is7xx_fifo_write(struct uart_port *port, u8 *txbuf, u8 to_send)
396396
{
397-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
397+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
398398

399399
/*
400400
* Don't send zero-length data, at least on SPI it confuses the chip
@@ -409,7 +409,7 @@ static void sc16is7xx_fifo_write(struct uart_port *port, u8 *txbuf, u8 to_send)
409409
static void sc16is7xx_port_update(struct uart_port *port, u8 reg,
410410
u8 mask, u8 val)
411411
{
412-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
412+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
413413

414414
regmap_update_bits(one->regmap, reg, mask, val);
415415
}
@@ -441,7 +441,7 @@ static void sc16is7xx_power(struct uart_port *port, int on)
441441
*/
442442
static void sc16is7xx_regs_lock(struct uart_port *port, u8 register_set)
443443
{
444-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
444+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
445445

446446
mutex_lock(&one->lock);
447447

@@ -457,7 +457,7 @@ static void sc16is7xx_regs_lock(struct uart_port *port, u8 register_set)
457457

458458
static void sc16is7xx_regs_unlock(struct uart_port *port)
459459
{
460-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
460+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
461461

462462
/* Re-enable cache updates when writing to general registers */
463463
regcache_cache_bypass(one->regmap, false);
@@ -471,7 +471,7 @@ static void sc16is7xx_regs_unlock(struct uart_port *port)
471471
static void sc16is7xx_ier_clear(struct uart_port *port, u8 bit)
472472
{
473473
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);
475475

476476
lockdep_assert_held_once(&port->lock);
477477

@@ -484,7 +484,7 @@ static void sc16is7xx_ier_clear(struct uart_port *port, u8 bit)
484484
static void sc16is7xx_ier_set(struct uart_port *port, u8 bit)
485485
{
486486
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);
488488

489489
lockdep_assert_held_once(&port->lock);
490490

@@ -615,7 +615,7 @@ static int sc16is7xx_set_baud(struct uart_port *port, int baud)
615615
static void sc16is7xx_handle_rx(struct uart_port *port, unsigned int rxlen,
616616
unsigned int iir)
617617
{
618-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
618+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
619619
unsigned int lsr = 0, bytes_read, i;
620620
bool read_lsr = (iir == SC16IS7XX_IIR_RLSE_SRC);
621621
u8 ch, flag;
@@ -782,7 +782,7 @@ static bool sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno)
782782
{
783783
unsigned int iir, rxlen;
784784
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);
786786

787787
guard(mutex)(&one->lock);
788788

@@ -862,8 +862,8 @@ static void sc16is7xx_poll_proc(struct kthread_work *ws)
862862

863863
static void sc16is7xx_tx_proc(struct kthread_work *ws)
864864
{
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;
867867

868868
if ((port->rs485.flags & SER_RS485_ENABLED) &&
869869
(port->rs485.delay_rts_before_send > 0))
@@ -895,7 +895,7 @@ static void sc16is7xx_reconf_rs485(struct uart_port *port)
895895

896896
static void sc16is7xx_reg_proc(struct kthread_work *ws)
897897
{
898-
struct sc16is7xx_one *one = to_sc16is7xx_one(ws, reg_work);
898+
struct sc16is7xx_one *one = container_of(ws, struct sc16is7xx_one, reg_work);
899899
struct sc16is7xx_one_config config;
900900
unsigned long irqflags;
901901

@@ -933,7 +933,7 @@ static void sc16is7xx_reg_proc(struct kthread_work *ws)
933933

934934
static void sc16is7xx_ms_proc(struct kthread_work *ws)
935935
{
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);
937937
struct sc16is7xx_port *s = dev_get_drvdata(one->port.dev);
938938

939939
if (one->port.state) {
@@ -946,7 +946,7 @@ static void sc16is7xx_ms_proc(struct kthread_work *ws)
946946

947947
static void sc16is7xx_enable_ms(struct uart_port *port)
948948
{
949-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
949+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
950950
struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
951951

952952
lockdep_assert_held_once(&port->lock);
@@ -957,7 +957,7 @@ static void sc16is7xx_enable_ms(struct uart_port *port)
957957
static void sc16is7xx_start_tx(struct uart_port *port)
958958
{
959959
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);
961961

962962
kthread_queue_work(&s->kworker, &one->tx_work);
963963
}
@@ -996,7 +996,7 @@ static unsigned int sc16is7xx_tx_empty(struct uart_port *port)
996996

997997
static unsigned int sc16is7xx_get_mctrl(struct uart_port *port)
998998
{
999-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
999+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
10001000

10011001
/* Called with port lock taken so we can only return cached value */
10021002
return one->old_mctrl;
@@ -1005,7 +1005,7 @@ static unsigned int sc16is7xx_get_mctrl(struct uart_port *port)
10051005
static void sc16is7xx_set_mctrl(struct uart_port *port, unsigned int mctrl)
10061006
{
10071007
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);
10091009

10101010
one->config.flags |= SC16IS7XX_RECONF_MD;
10111011
kthread_queue_work(&s->kworker, &one->reg_work);
@@ -1022,7 +1022,7 @@ static void sc16is7xx_set_termios(struct uart_port *port,
10221022
struct ktermios *termios,
10231023
const struct ktermios *old)
10241024
{
1025-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
1025+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
10261026
unsigned int lcr, flow = 0;
10271027
int baud;
10281028
unsigned long flags;
@@ -1125,7 +1125,7 @@ static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termi
11251125
struct serial_rs485 *rs485)
11261126
{
11271127
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);
11291129

11301130
if (rs485->flags & SER_RS485_ENABLED) {
11311131
/*
@@ -1145,7 +1145,7 @@ static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termi
11451145

11461146
static int sc16is7xx_startup(struct uart_port *port)
11471147
{
1148-
struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
1148+
struct sc16is7xx_one *one = to_sc16is7xx_one(port);
11491149
struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
11501150
unsigned int val;
11511151
unsigned long flags;
@@ -1209,7 +1209,7 @@ static int sc16is7xx_startup(struct uart_port *port)
12091209
static void sc16is7xx_shutdown(struct uart_port *port)
12101210
{
12111211
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);
12131213

12141214
kthread_cancel_delayed_work_sync(&one->ms_work);
12151215

0 commit comments

Comments
 (0)