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>
This commit is contained in:
committed by
Bjorn Helgaas
parent
035fff1f7a
commit
e7a7499d84
@@ -53,7 +53,7 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
|
|||||||
if (pdev->p2pdma->pool)
|
if (pdev->p2pdma->pool)
|
||||||
size = gen_pool_size(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);
|
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)
|
if (pdev->p2pdma->pool)
|
||||||
avail = gen_pool_avail(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);
|
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);
|
struct pci_dev *pdev = to_pci_dev(dev);
|
||||||
|
|
||||||
return snprintf(buf, PAGE_SIZE, "%d\n",
|
return scnprintf(buf, PAGE_SIZE, "%d\n",
|
||||||
pdev->p2pdma->p2pmem_published);
|
pdev->p2pdma->p2pmem_published);
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(published);
|
static DEVICE_ATTR_RO(published);
|
||||||
|
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ static ssize_t driver_override_show(struct device *dev,
|
|||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
device_lock(dev);
|
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);
|
device_unlock(dev);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6347,7 +6347,7 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
|
|||||||
|
|
||||||
spin_lock(&resource_alignment_lock);
|
spin_lock(&resource_alignment_lock);
|
||||||
if (resource_alignment_param)
|
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);
|
spin_unlock(&resource_alignment_lock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user