* [PATCH 1/3] PCI: Replace use of snprintf() with scnprintf() in resource_alignment_show()
2020-08-24 23:39 [PATCH 0/3] PCI: Replace use of snprintf() with scnprintf() in show() functions Krzysztof Wilczyński
@ 2020-08-24 23:39 ` Krzysztof Wilczyński
2020-08-24 23:39 ` [PATCH 2/3] PCI: sysfs: Replace use of snprintf() with scnprintf() in driver_override_show() Krzysztof Wilczyński
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Wilczyński @ 2020-08-24 23:39 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci
Replace use of snprintf() with scnprintf() 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().
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/pci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e39c5499770f..e6c904cbf983 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6350,7 +6350,7 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
spin_lock(&resource_alignment_lock);
if (resource_alignment_param)
- count = snprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
+ count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
spin_unlock(&resource_alignment_lock);
/*
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] PCI: sysfs: Replace use of snprintf() with scnprintf() in driver_override_show()
2020-08-24 23:39 [PATCH 0/3] PCI: Replace use of snprintf() with scnprintf() in show() functions Krzysztof Wilczyński
2020-08-24 23:39 ` [PATCH 1/3] PCI: Replace use of snprintf() with scnprintf() in resource_alignment_show() Krzysztof Wilczyński
@ 2020-08-24 23:39 ` Krzysztof Wilczyński
2020-08-24 23:39 ` [PATCH 3/3] PCI/P2PDMA: Replace use of snprintf() with scnprintf() in show() functions Krzysztof Wilczyński
2020-09-01 19:05 ` [PATCH 0/3] PCI: " Bjorn Helgaas
3 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Wilczyński @ 2020-08-24 23:39 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci
Replace use of snprintf() with scnprintf() 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().
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/pci-sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 6d78df981d41..ed66d387e913 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -574,7 +574,7 @@ static ssize_t driver_override_show(struct device *dev,
ssize_t len;
device_lock(dev);
- len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
+ len = scnprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
device_unlock(dev);
return len;
}
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] PCI/P2PDMA: Replace use of snprintf() with scnprintf() in show() functions
2020-08-24 23:39 [PATCH 0/3] PCI: Replace use of snprintf() with scnprintf() in show() functions Krzysztof Wilczyński
2020-08-24 23:39 ` [PATCH 1/3] PCI: Replace use of snprintf() with scnprintf() in resource_alignment_show() Krzysztof Wilczyński
2020-08-24 23:39 ` [PATCH 2/3] PCI: sysfs: Replace use of snprintf() with scnprintf() in driver_override_show() Krzysztof Wilczyński
@ 2020-08-24 23:39 ` Krzysztof Wilczyński
2020-09-01 19:05 ` [PATCH 0/3] PCI: " Bjorn Helgaas
3 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Wilczyński @ 2020-08-24 23:39 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci
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 --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);
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] PCI: Replace use of snprintf() with scnprintf() in show() functions
2020-08-24 23:39 [PATCH 0/3] PCI: Replace use of snprintf() with scnprintf() in show() functions Krzysztof Wilczyński
` (2 preceding siblings ...)
2020-08-24 23:39 ` [PATCH 3/3] PCI/P2PDMA: Replace use of snprintf() with scnprintf() in show() functions Krzysztof Wilczyński
@ 2020-09-01 19:05 ` Bjorn Helgaas
3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2020-09-01 19:05 UTC (permalink / raw)
To: Krzysztof Wilczyński; +Cc: Bjorn Helgaas, linux-pci
On Mon, Aug 24, 2020 at 11:39:15PM +0000, Krzysztof Wilczyński wrote:
> Replace use of snprintf() with scnprintf() 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, for example:
>
> 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
>
> Krzysztof Wilczyński (3):
> PCI: Replace use of snprintf() with scnprintf() in
> resource_alignment_show()
> PCI: sysfs: Replace use of snprintf() with scnprintf() in
> driver_override_show()
> PCI/P2PDMA: Replace use of snprintf() with scnprintf() in show()
> functions
>
> drivers/pci/p2pdma.c | 8 ++++----
> drivers/pci/pci-sysfs.c | 2 +-
> drivers/pci/pci.c | 2 +-
> 3 files changed, 6 insertions(+), 6 deletions(-)
Squashed together and applied to pci/misc for v5.10, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread