virtio_console: Get rid of unneeded temporary variable
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 10 Feb 2025 09:59:45 +0000 (11:59 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 20 Feb 2025 14:24:25 +0000 (15:24 +0100)
When compiling a kernel with GCC using `make W=1` with CONFIG_WERROR=y
(which is default nowadays), the build fails:

drivers/char/virtio_console.c:1427:9: note: ‘snprintf’ output between 9 and 27 bytes into a destination of size 16

Indeed, GCC can't see the limits of the variables that are in use.
Fix this by using dev_name() of the newly created device that is
luckily the same as the string used for the DebugFS node name.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Amit Shah <amit@kernel.org>
Link: https://lore.kernel.org/r/20250210095946.4122771-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/virtio_console.c

index 35af0cc11d9341ca522dc96fdb6f736cd7b6df54..9e6cee6082b576471b62beb38895aefc847f9734 100644 (file)
@@ -1321,7 +1321,6 @@ static void send_sigio_to_port(struct port *port)
 
 static int add_port(struct ports_device *portdev, u32 id)
 {
-       char debugfs_name[16];
        struct port *port;
        dev_t devt;
        int err;
@@ -1424,9 +1423,7 @@ static int add_port(struct ports_device *portdev, u32 id)
         * Finally, create the debugfs file that we can use to
         * inspect a port's state at any time
         */
-       snprintf(debugfs_name, sizeof(debugfs_name), "vport%up%u",
-                port->portdev->vdev->index, id);
-       port->debugfs_file = debugfs_create_file(debugfs_name, 0444,
+       port->debugfs_file = debugfs_create_file(dev_name(port->dev), 0444,
                                                 pdrvdata.debugfs_dir,
                                                 port, &port_debugfs_fops);
        return 0;