tty: move from strlcpy with unused retval to strscpy
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 18 Aug 2022 21:01:12 +0000 (23:01 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 Aug 2022 12:21:59 +0000 (14:21 +0200)
Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Link: https://lore.kernel.org/r/20220818210113.7469-1-wsa+renesas@sang-engineering.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/hvc/hvcs.c
drivers/tty/serial/earlycon.c
drivers/tty/serial/serial_core.c
drivers/tty/serial/sunsu.c
drivers/tty/serial/sunzilog.c

index 9b7e8246a464a98a5bab02f4bdf6c4e071e5c3fc..b79ce8d34f119744ac1fb35bff78cedc4d0b8db6 100644 (file)
@@ -839,7 +839,7 @@ static void hvcs_set_pi(struct hvcs_partner_info *pi, struct hvcs_struct *hvcsd)
        hvcsd->p_partition_ID  = pi->partition_ID;
 
        /* copy the null-term char too */
-       strlcpy(hvcsd->p_location_code, pi->location_code,
+       strscpy(hvcsd->p_location_code, pi->location_code,
                sizeof(hvcsd->p_location_code));
 }
 
index 88d08ba1ca83752bbe446b50359df6ba2dd017db..a5f380584cdae7a1835495eb6e4fc7d6bd003783 100644 (file)
@@ -67,7 +67,7 @@ static void __init earlycon_init(struct earlycon_device *device,
        if (*s)
                earlycon->index = simple_strtoul(s, NULL, 10);
        len = s - name;
-       strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
+       strscpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
        earlycon->data = &early_console_dev;
 }
 
@@ -123,7 +123,7 @@ static int __init parse_options(struct earlycon_device *device, char *options)
                device->baud = simple_strtoul(options, NULL, 0);
                length = min(strcspn(options, " ") + 1,
                             (size_t)(sizeof(device->options)));
-               strlcpy(device->options, options, length);
+               strscpy(device->options, options, length);
        }
 
        return 0;
@@ -304,7 +304,7 @@ int __init of_setup_earlycon(const struct earlycon_id *match,
 
        if (options) {
                early_console_dev.baud = simple_strtoul(options, NULL, 0);
-               strlcpy(early_console_dev.options, options,
+               strscpy(early_console_dev.options, options,
                        sizeof(early_console_dev.options));
        }
        earlycon_init(&early_console_dev, match->name);
index 12c87cd201a7659e958258629f99214eacd01b94..3561a160cbd5f51a4fbc7d54f3e684578a783568 100644 (file)
@@ -2497,7 +2497,7 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
                         "MMIO 0x%llx", (unsigned long long)port->mapbase);
                break;
        default:
-               strlcpy(address, "*unknown*", sizeof(address));
+               strscpy(address, "*unknown*", sizeof(address));
                break;
        }
 
index 84d545e5a8c7b31b94980e26121ea7d0ea31b266..d5dcb612804e178619c87884a5aa0b0247f564c5 100644 (file)
@@ -1217,13 +1217,13 @@ static int sunsu_kbd_ms_init(struct uart_sunsu_port *up)
        serio->id.type = SERIO_RS232;
        if (up->su_type == SU_PORT_KBD) {
                serio->id.proto = SERIO_SUNKBD;
-               strlcpy(serio->name, "sukbd", sizeof(serio->name));
+               strscpy(serio->name, "sukbd", sizeof(serio->name));
        } else {
                serio->id.proto = SERIO_SUN;
                serio->id.extra = 1;
-               strlcpy(serio->name, "sums", sizeof(serio->name));
+               strscpy(serio->name, "sums", sizeof(serio->name));
        }
-       strlcpy(serio->phys,
+       strscpy(serio->phys,
                (!(up->port.line & 1) ? "su/serio0" : "su/serio1"),
                sizeof(serio->phys));
 
index c14275d83b0b4ca8919c0bd2d2f8a2ee61926c3d..c44cf613ff1aadfd23e9756f82d0687ff8fe43ce 100644 (file)
@@ -1307,13 +1307,13 @@ static void sunzilog_register_serio(struct uart_sunzilog_port *up)
        serio->id.type = SERIO_RS232;
        if (up->flags & SUNZILOG_FLAG_CONS_KEYB) {
                serio->id.proto = SERIO_SUNKBD;
-               strlcpy(serio->name, "zskbd", sizeof(serio->name));
+               strscpy(serio->name, "zskbd", sizeof(serio->name));
        } else {
                serio->id.proto = SERIO_SUN;
                serio->id.extra = 1;
-               strlcpy(serio->name, "zsms", sizeof(serio->name));
+               strscpy(serio->name, "zsms", sizeof(serio->name));
        }
-       strlcpy(serio->phys,
+       strscpy(serio->phys,
                ((up->flags & SUNZILOG_FLAG_CONS_KEYB) ?
                 "zs/serio0" : "zs/serio1"),
                sizeof(serio->phys));