2023-07-31 08:30:48

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 00/10] tty: minor cleanups

This is another round of minor cleanups in the tty/serial/related
drivers.

Jiri Slaby (SUSE) (10):
serial: move WARN_ON() in uart_write() to the condition
Bluetooth: rfcomm: remove casts from tty->driver_data
tty: hvsi: remove an extra variable from hvsi_write()
input: serport: remove casts from tty->disc_data
can: slcan: remove casts from tty->disc_data
serial: altera_jtaguart: switch status to u32
speakup: switch to unsigned iterator in spk_ttyio_receive_buf2()
misc: ti-st: remove forward declarations and make st_int_recv() static
misc: ti-st: remove ptr from recv functions
misc: ti-st: don't check for tty data == NULL

drivers/accessibility/speakup/spk_ttyio.c | 2 +-
drivers/input/serio/serport.c | 10 +++++-----
drivers/misc/ti-st/st_core.c | 11 +++--------
drivers/misc/ti-st/st_kim.c | 9 +--------
drivers/net/can/slcan/slcan-core.c | 8 ++++----
drivers/tty/hvc/hvsi.c | 3 +--
drivers/tty/serial/altera_jtaguart.c | 2 +-
drivers/tty/serial/serial_core.c | 8 ++------
net/bluetooth/rfcomm/tty.c | 22 +++++++++++-----------
9 files changed, 29 insertions(+), 46 deletions(-)

--
2.41.0



2023-07-31 08:30:56

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 04/10] input: serport: remove casts from tty->disc_data

tty->disc_data is 'void *', so there is no need to cast from that.
Therefore remove the casts and assign the pointer directly.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: [email protected]
---
drivers/input/serio/serport.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 7f7ef0e3a749..a5d8953f5904 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -103,7 +103,7 @@ static int serport_ldisc_open(struct tty_struct *tty)

static void serport_ldisc_close(struct tty_struct *tty)
{
- struct serport *serport = (struct serport *) tty->disc_data;
+ struct serport *serport = tty->disc_data;

kfree(serport);
}
@@ -117,7 +117,7 @@ static void serport_ldisc_close(struct tty_struct *tty)
static void serport_ldisc_receive(struct tty_struct *tty,
const unsigned char *cp, const char *fp, int count)
{
- struct serport *serport = (struct serport*) tty->disc_data;
+ struct serport *serport = tty->disc_data;
unsigned long flags;
unsigned int ch_flags = 0;
int i;
@@ -161,7 +161,7 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file,
unsigned char *kbuf, size_t nr,
void **cookie, unsigned long offset)
{
- struct serport *serport = (struct serport*) tty->disc_data;
+ struct serport *serport = tty->disc_data;
struct serio *serio;

if (test_and_set_bit(SERPORT_BUSY, &serport->flags))
@@ -245,7 +245,7 @@ static int serport_ldisc_compat_ioctl(struct tty_struct *tty,

static void serport_ldisc_hangup(struct tty_struct *tty)
{
- struct serport *serport = (struct serport *) tty->disc_data;
+ struct serport *serport = tty->disc_data;
unsigned long flags;

spin_lock_irqsave(&serport->lock, flags);
@@ -257,7 +257,7 @@ static void serport_ldisc_hangup(struct tty_struct *tty)

static void serport_ldisc_write_wakeup(struct tty_struct * tty)
{
- struct serport *serport = (struct serport *) tty->disc_data;
+ struct serport *serport = tty->disc_data;
unsigned long flags;

spin_lock_irqsave(&serport->lock, flags);
--
2.41.0


2023-07-31 08:31:02

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 03/10] tty: hvsi: remove an extra variable from hvsi_write()

'source' is the same as 'buf'. Rename the parameter ('buf') to
'source' and drop the local variable.

Likely, the two were introduced to have a different type. But 'char' and
'unsigned char' are the same in the kernel for a long time.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: [email protected]
---
drivers/tty/hvc/hvsi.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index a200d01eceed..c1b8a4fd8b1e 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -905,10 +905,9 @@ static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty)
}

static int hvsi_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+ const unsigned char *source, int count)
{
struct hvsi_struct *hp = tty->driver_data;
- const char *source = buf;
unsigned long flags;
int total = 0;
int origcount = count;
--
2.41.0


2023-07-31 08:31:08

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 05/10] can: slcan: remove casts from tty->disc_data

tty->disc_data is 'void *', so there is no need to cast from that.
Therefore remove the casts and assign the pointer directly.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Dario Binacchi <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
drivers/net/can/slcan/slcan-core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
index f4db77007c13..371af9d17b14 100644
--- a/drivers/net/can/slcan/slcan-core.c
+++ b/drivers/net/can/slcan/slcan-core.c
@@ -583,7 +583,7 @@ static void slcan_transmit(struct work_struct *work)
*/
static void slcan_write_wakeup(struct tty_struct *tty)
{
- struct slcan *sl = (struct slcan *)tty->disc_data;
+ struct slcan *sl = tty->disc_data;

schedule_work(&sl->tx_work);
}
@@ -778,7 +778,7 @@ static void slcan_receive_buf(struct tty_struct *tty,
const unsigned char *cp, const char *fp,
int count)
{
- struct slcan *sl = (struct slcan *)tty->disc_data;
+ struct slcan *sl = tty->disc_data;

if (!netif_running(sl->dev))
return;
@@ -862,7 +862,7 @@ static int slcan_open(struct tty_struct *tty)
*/
static void slcan_close(struct tty_struct *tty)
{
- struct slcan *sl = (struct slcan *)tty->disc_data;
+ struct slcan *sl = tty->disc_data;

unregister_candev(sl->dev);

@@ -886,7 +886,7 @@ static void slcan_close(struct tty_struct *tty)
static int slcan_ioctl(struct tty_struct *tty, unsigned int cmd,
unsigned long arg)
{
- struct slcan *sl = (struct slcan *)tty->disc_data;
+ struct slcan *sl = tty->disc_data;
unsigned int tmp;

switch (cmd) {
--
2.41.0


2023-07-31 08:31:08

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 06/10] serial: altera_jtaguart: switch status to u32

'status' is assigned a result from readl(). There is no need for the
variable to be 'unsigned long'. readl() returns 32bit values.

Provided, this is a Nios II driver (32-bit), there is no change in
semantics. This only makes the type explicit.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Tobias Klauser <[email protected]>
---
drivers/tty/serial/altera_jtaguart.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/altera_jtaguart.c b/drivers/tty/serial/altera_jtaguart.c
index 6203ca1de769..5fab4c978891 100644
--- a/drivers/tty/serial/altera_jtaguart.c
+++ b/drivers/tty/serial/altera_jtaguart.c
@@ -110,7 +110,7 @@ static void altera_jtaguart_set_termios(struct uart_port *port,

static void altera_jtaguart_rx_chars(struct uart_port *port)
{
- unsigned long status;
+ u32 status;
u8 ch;

while ((status = readl(port->membase + ALTERA_JTAGUART_DATA_REG)) &
--
2.41.0


2023-07-31 08:31:09

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 07/10] speakup: switch to unsigned iterator in spk_ttyio_receive_buf2()

Now, that spk_ttyio_receive_buf2() receives an unsigned count, the
iterator can/should be unsigned too. Switch to that to be explicit.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: William Hubbs <[email protected]>
Cc: Chris Brannon <[email protected]>
Cc: Kirk Reiser <[email protected]>
Cc: Samuel Thibault <[email protected]>
Cc: [email protected]
---
drivers/accessibility/speakup/spk_ttyio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 07373b3debd1..5d4bafe118ec 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -79,7 +79,7 @@ static int spk_ttyio_receive_buf2(struct tty_struct *tty,
struct spk_synth *synth = ldisc_data->synth;

if (synth->read_buff_add) {
- int i;
+ unsigned int i;

for (i = 0; i < count; i++)
synth->read_buff_add(cp[i]);
--
2.41.0


2023-07-31 08:33:01

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH 05/10] can: slcan: remove casts from tty->disc_data

On 31.07.2023 10:02:39, Jiri Slaby (SUSE) wrote:
> tty->disc_data is 'void *', so there is no need to cast from that.
> Therefore remove the casts and assign the pointer directly.
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> Cc: Dario Binacchi <[email protected]>
> Cc: Wolfgang Grandegger <[email protected]>
> Cc: Marc Kleine-Budde <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: [email protected]
> Cc: [email protected]

Acked-by: Marc Kleine-Budde <[email protected]>

regards,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |


Attachments:
(No filename) (968.00 B)
signature.asc (499.00 B)
Download all attachments

2023-07-31 08:57:27

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 09/10] misc: ti-st: remove ptr from recv functions

ptr is the same as data, so use ptr directly as a parameter and drop the
useless local variable.

Likely, the two were introduced to have a different type. But 'char' and
'unsigned char' are the same in the kernel for a long time.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
drivers/misc/ti-st/st_core.c | 4 +---
drivers/misc/ti-st/st_kim.c | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 389901276ce3..e2add50b191c 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -224,9 +224,8 @@ static inline void st_wakeup_ack(struct st_data_s *st_gdata,
* CH-8 packets from FM, CH-9 packets from GPS cores.
*/
static void st_int_recv(void *disc_data,
- const unsigned char *data, long count)
+ const unsigned char *ptr, long count)
{
- char *ptr;
struct st_proto_s *proto;
unsigned short payload_len = 0;
int len = 0;
@@ -235,7 +234,6 @@ static void st_int_recv(void *disc_data,
struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
unsigned long flags;

- ptr = (char *)data;
/* tty_receive sent null ? */
if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
pr_err(" received null from TTY ");
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index f2f6cab97c08..8c801897ffa2 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -128,15 +128,13 @@ static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
* tty_receive and hence the logic
*/
static void kim_int_recv(struct kim_data_s *kim_gdata,
- const unsigned char *data, long count)
+ const unsigned char *ptr, long count)
{
- const unsigned char *ptr;
int len = 0;
unsigned char *plen;

pr_debug("%s", __func__);
/* Decode received bytes here */
- ptr = data;
if (unlikely(ptr == NULL)) {
pr_err(" received null from TTY ");
return;
--
2.41.0


2023-07-31 08:57:36

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 10/10] misc: ti-st: don't check for tty data == NULL

tty data passed to tty_ldisc_ops::receive_buf() are never NULL. Remove
this check.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
drivers/misc/ti-st/st_core.c | 3 +--
drivers/misc/ti-st/st_kim.c | 5 -----
2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index e2add50b191c..3b2145722bd7 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -234,8 +234,7 @@ static void st_int_recv(void *disc_data,
struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
unsigned long flags;

- /* tty_receive sent null ? */
- if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
+ if (st_gdata == NULL) {
pr_err(" received null from TTY ");
return;
}
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 8c801897ffa2..5431a89924aa 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -135,11 +135,6 @@ static void kim_int_recv(struct kim_data_s *kim_gdata,

pr_debug("%s", __func__);
/* Decode received bytes here */
- if (unlikely(ptr == NULL)) {
- pr_err(" received null from TTY ");
- return;
- }
-
while (count) {
if (kim_gdata->rx_count) {
len = min_t(unsigned int, kim_gdata->rx_count, count);
--
2.41.0


2023-07-31 09:01:31

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 00/10] tty: minor cleanups

On 31. 07. 23, 10:15, Marc Kleine-Budde wrote:
> On 31.07.2023 10:02:34, Jiri Slaby (SUSE) wrote:
>> can: slcan: remove casts from tty->disc_data
>
> You can do the same for drivers/net/can/can327.c

OK. And in net/nfc/nci/uart.c and that all should be it.

thanks,
--
js
suse labs


2023-07-31 09:01:54

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 08/10] misc: ti-st: remove forward declarations and make st_int_recv() static

st_kim_recv() is already declared in linux/ti_wilink_st.h. Given that is
already included in st_core.c, drop the re-declaration from there.

st_int_recv() is used only in st_core.c and the forward declaration is
not needed. So drop the declaration and make the function static.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
drivers/misc/ti-st/st_core.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 01d2257deea4..389901276ce3 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -16,8 +16,6 @@

#include <linux/ti_wilink_st.h>

-extern void st_kim_recv(void *, const unsigned char *, long);
-void st_int_recv(void *, const unsigned char *, long);
/*
* function pointer pointing to either,
* st_kim_recv during registration to receive fw download responses
@@ -225,7 +223,7 @@ static inline void st_wakeup_ack(struct st_data_s *st_gdata,
* HCI-Events, ACL, SCO, 4 types of HCI-LL PM packets
* CH-8 packets from FM, CH-9 packets from GPS cores.
*/
-void st_int_recv(void *disc_data,
+static void st_int_recv(void *disc_data,
const unsigned char *data, long count)
{
char *ptr;
--
2.41.0


2023-07-31 09:02:13

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH 00/10] tty: minor cleanups

On 31.07.2023 10:02:34, Jiri Slaby (SUSE) wrote:
> can: slcan: remove casts from tty->disc_data

You can do the same for drivers/net/can/can327.c

Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |


Attachments:
(No filename) (428.00 B)
signature.asc (499.00 B)
Download all attachments

2023-07-31 19:10:31

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 04/10] input: serport: remove casts from tty->disc_data

On Mon, Jul 31, 2023 at 10:02:38AM +0200, Jiri Slaby (SUSE) wrote:
> tty->disc_data is 'void *', so there is no need to cast from that.
> Therefore remove the casts and assign the pointer directly.
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> Cc: Dmitry Torokhov <[email protected]>
> Cc: [email protected]

Acked-by: Dmitry Torokhov <[email protected]>

Thanks.

--
Dmitry

2023-08-08 17:57:38

by Tobias Klauser

[permalink] [raw]
Subject: Re: [PATCH 06/10] serial: altera_jtaguart: switch status to u32

On 2023-07-31 at 10:02:40 +0200, Jiri Slaby (SUSE) <[email protected]> wrote:
> 'status' is assigned a result from readl(). There is no need for the
> variable to be 'unsigned long'. readl() returns 32bit values.
>
> Provided, this is a Nios II driver (32-bit), there is no change in
> semantics. This only makes the type explicit.
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> Cc: Tobias Klauser <[email protected]>

Acked-by: Tobias Klauser <[email protected]>