]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: Use scnprintf() instead of sprintf()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 19 Dec 2025 17:40:32 +0000 (19:40 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 27 Jan 2026 22:36:53 +0000 (16:36 -0600)
Using sprintf() is deprecated as it does not do proper size checks.  While
the code in pci_scan_bridge_extend() is safe with respect to overwriting
the destination buffer, use scnprintf() to not promote use of a deprecated
sprint() (and allow eventually removing it from the kernel).

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20251219174036.16738-20-ilpo.jarvinen@linux.intel.com
drivers/pci/probe.c

index ad5ae05aad3c8580bc8182700440f831d9f565d6..ed4d268336409ada47f4a6ff51a0fdf412dcfcc7 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/platform_device.h>
 #include <linux/pci_hotplug.h>
 #include <linux/slab.h>
+#include <linux/sprintf.h>
 #include <linux/module.h>
 #include <linux/cpumask.h>
 #include <linux/aer.h>
@@ -1571,9 +1572,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
                pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max);
        }
 
-       sprintf(child->name,
-               (is_cardbus ? "PCI CardBus %04x:%02x" : "PCI Bus %04x:%02x"),
-               pci_domain_nr(bus), child->number);
+       scnprintf(child->name, sizeof(child->name),
+                 (is_cardbus ? "PCI CardBus %04x:%02x" : "PCI Bus %04x:%02x"),
+                 pci_domain_nr(bus), child->number);
 
        /* Check that all devices are accessible */
        while (bus->parent) {