diff mbox series

[3/3] PCI/P2PDMA: Replace use of snprintf() with scnprintf() in show() functions

Message ID 20200824233918.26306-4-kw@linux.com
State New
Headers show
Series PCI: Replace use of snprintf() with scnprintf() in show() functions | expand

Commit Message

Krzysztof Wilczyński Aug. 24, 2020, 11:39 p.m. UTC
Replace use of snprintf() with scnprintf() in the functions size_show(),
available_show() and published_show() in order to adhere to the rules in
Documentation/filesystems/sysfs.txt, as per:

  show() must not use snprintf() when formatting the value to be
  returned to user space. If you can guarantee that an overflow
  will never happen you can use sprintf() otherwise you must use
  scnprintf().

Also resolve the following Coccinelle warnings:

  drivers/pci/p2pdma.c:69:8-16: WARNING: use scnprintf or sprintf
  drivers/pci/p2pdma.c:78:8-16: WARNING: use scnprintf or sprintf
  drivers/pci/p2pdma.c:56:8-16: WARNING: use scnprintf or sprintf

The Coccinelle warning was added in commit abfc19ff202d ("coccinelle:
api: add device_attr_show script").

There is no change to the functionality.

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

Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
 drivers/pci/p2pdma.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index f357f9a32b3a..c4714438d39c 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -53,7 +53,7 @@  static ssize_t size_show(struct device *dev, struct device_attribute *attr,
 	if (pdev->p2pdma->pool)
 		size = gen_pool_size(pdev->p2pdma->pool);
 
-	return snprintf(buf, PAGE_SIZE, "%zd\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%zd\n", size);
 }
 static DEVICE_ATTR_RO(size);
 
@@ -66,7 +66,7 @@  static ssize_t available_show(struct device *dev, struct device_attribute *attr,
 	if (pdev->p2pdma->pool)
 		avail = gen_pool_avail(pdev->p2pdma->pool);
 
-	return snprintf(buf, PAGE_SIZE, "%zd\n", avail);
+	return scnprintf(buf, PAGE_SIZE, "%zd\n", avail);
 }
 static DEVICE_ATTR_RO(available);
 
@@ -75,8 +75,8 @@  static ssize_t published_show(struct device *dev, struct device_attribute *attr,
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
-			pdev->p2pdma->p2pmem_published);
+	return scnprintf(buf, PAGE_SIZE, "%d\n",
+			 pdev->p2pdma->p2pmem_published);
 }
 static DEVICE_ATTR_RO(published);