public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] virtio_console: Get rid of unneeded temporary variable
@ 2025-02-10  9:59 Andy Shevchenko
  2025-02-12 12:19 ` Amit Shah
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2025-02-10  9:59 UTC (permalink / raw)
  To: virtualization, linux-kernel
  Cc: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman, Andy Shevchenko

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>
---
 drivers/char/virtio_console.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 24442485e73e..707464d2227c 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -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;
-- 
2.45.1.3035.g276e886db78b


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1 1/1] virtio_console: Get rid of unneeded temporary variable
  2025-02-10  9:59 [PATCH v1 1/1] virtio_console: Get rid of unneeded temporary variable Andy Shevchenko
@ 2025-02-12 12:19 ` Amit Shah
  0 siblings, 0 replies; 2+ messages in thread
From: Amit Shah @ 2025-02-12 12:19 UTC (permalink / raw)
  To: Andy Shevchenko, virtualization, linux-kernel
  Cc: Arnd Bergmann, Greg Kroah-Hartman

On Mon, 2025-02-10 at 11:59 +0200, Andy Shevchenko wrote:
> 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>
> ---
>  drivers/char/virtio_console.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Reviewed-by: Amit Shah <amit@kernel.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-12 12:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10  9:59 [PATCH v1 1/1] virtio_console: Get rid of unneeded temporary variable Andy Shevchenko
2025-02-12 12:19 ` Amit Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox