Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: Use scnprintf(), not snprintf(), in sysfs "show" functions

Sysfs "show" methods should return the number of bytes printed into the
buffer. This is the return value of scnprintf() [1].

snprintf(buf, size, ...) prints at most "size" bytes into "buf", but
returns the number of bytes that *would* be printed if "buf" were large
enough.

Replace use of snprintf() with scnprintf(). No functional change intended.

Related:
https://patchwork.kernel.org/patch/9946759/#20969333
https://lwn.net/Articles/69419

[1] Documentation/filesystems/sysfs.rst

[bhelgaas: squashed, commit log]
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://lore.kernel.org/r/20200824233918.26306-2-kw@linux.com
Link: https://lore.kernel.org/r/20200824233918.26306-3-kw@linux.com
Link: https://lore.kernel.org/r/20200824233918.26306-4-kw@linux.com
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Krzysztof Wilczyński and committed by
Bjorn Helgaas
e7a7499d 035fff1f

+6 -6
+4 -4
drivers/pci/p2pdma.c
··· 53 53 if (pdev->p2pdma->pool) 54 54 size = gen_pool_size(pdev->p2pdma->pool); 55 55 56 - return snprintf(buf, PAGE_SIZE, "%zd\n", size); 56 + return scnprintf(buf, PAGE_SIZE, "%zd\n", size); 57 57 } 58 58 static DEVICE_ATTR_RO(size); 59 59 ··· 66 66 if (pdev->p2pdma->pool) 67 67 avail = gen_pool_avail(pdev->p2pdma->pool); 68 68 69 - return snprintf(buf, PAGE_SIZE, "%zd\n", avail); 69 + return scnprintf(buf, PAGE_SIZE, "%zd\n", avail); 70 70 } 71 71 static DEVICE_ATTR_RO(available); 72 72 ··· 75 75 { 76 76 struct pci_dev *pdev = to_pci_dev(dev); 77 77 78 - return snprintf(buf, PAGE_SIZE, "%d\n", 79 - pdev->p2pdma->p2pmem_published); 78 + return scnprintf(buf, PAGE_SIZE, "%d\n", 79 + pdev->p2pdma->p2pmem_published); 80 80 } 81 81 static DEVICE_ATTR_RO(published); 82 82
+1 -1
drivers/pci/pci-sysfs.c
··· 574 574 ssize_t len; 575 575 576 576 device_lock(dev); 577 - len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); 577 + len = scnprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); 578 578 device_unlock(dev); 579 579 return len; 580 580 }
+1 -1
drivers/pci/pci.c
··· 6347 6347 6348 6348 spin_lock(&resource_alignment_lock); 6349 6349 if (resource_alignment_param) 6350 - count = snprintf(buf, PAGE_SIZE, "%s", resource_alignment_param); 6350 + count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param); 6351 6351 spin_unlock(&resource_alignment_lock); 6352 6352 6353 6353 /*