From: "Krzysztof Wilczyński" <kw@linux.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Logan Gunthorpe <logang@deltatee.com>,
Joe Perches <joe@perches.com>,
"Oliver O'Halloran" <oohall@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Tyrel Datwyler <tyreld@linux.ibm.com>,
Russell Currey <ruscur@russell.cc>,
Kurt Schwemmer <kurt.schwemmer@microsemi.com>,
Vidya Sagar <vidyas@nvidia.com>,
Xiongfeng Wang <wangxiongfeng2@huawei.com>,
linux-pci@vger.kernel.org
Subject: [PATCH v3 11/14] PCI: shpchp: Use sysfs_emit() and sysfs_emit_at() in "show" functions
Date: Tue, 18 May 2021 03:41:06 +0000 [thread overview]
Message-ID: <20210518034109.158450-11-kw@linux.com> (raw)
In-Reply-To: <20210518034109.158450-1-kw@linux.com>
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].
Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.
No functional change intended.
[1] Documentation/filesystems/sysfs.rst
Related to:
commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions")
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
---
Changes in v2:
None.
Changes in v3:
Added Logan Gunthorpe's "Reviewed-by".
drivers/pci/hotplug/shpchp_sysfs.c | 38 +++++++++++++++++-------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c
index 45658bb5c554..64beed7a26be 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -24,50 +24,54 @@
static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
{
struct pci_dev *pdev;
- char *out = buf;
int index, busnr;
struct resource *res;
struct pci_bus *bus;
+ size_t len = 0;
pdev = to_pci_dev(dev);
bus = pdev->subordinate;
- out += sprintf(buf, "Free resources: memory\n");
+ len += sysfs_emit_at(buf, len, "Free resources: memory\n");
pci_bus_for_each_resource(bus, res, index) {
if (res && (res->flags & IORESOURCE_MEM) &&
!(res->flags & IORESOURCE_PREFETCH)) {
- out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
- (unsigned long long)res->start,
- (unsigned long long)resource_size(res));
+ len += sysfs_emit_at(buf, len,
+ "start = %8.8llx, length = %8.8llx\n",
+ (unsigned long long)res->start,
+ (unsigned long long)resource_size(res));
}
}
- out += sprintf(out, "Free resources: prefetchable memory\n");
+ len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
pci_bus_for_each_resource(bus, res, index) {
if (res && (res->flags & IORESOURCE_MEM) &&
(res->flags & IORESOURCE_PREFETCH)) {
- out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
- (unsigned long long)res->start,
- (unsigned long long)resource_size(res));
+ len += sysfs_emit_at(buf, len,
+ "start = %8.8llx, length = %8.8llx\n",
+ (unsigned long long)res->start,
+ (unsigned long long)resource_size(res));
}
}
- out += sprintf(out, "Free resources: IO\n");
+ len += sysfs_emit_at(buf, len, "Free resources: IO\n");
pci_bus_for_each_resource(bus, res, index) {
if (res && (res->flags & IORESOURCE_IO)) {
- out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
- (unsigned long long)res->start,
- (unsigned long long)resource_size(res));
+ len += sysfs_emit_at(buf, len,
+ "start = %8.8llx, length = %8.8llx\n",
+ (unsigned long long)res->start,
+ (unsigned long long)resource_size(res));
}
}
- out += sprintf(out, "Free resources: bus numbers\n");
+ len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n");
for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
if (!pci_find_bus(pci_domain_nr(bus), busnr))
break;
}
if (busnr < bus->busn_res.end)
- out += sprintf(out, "start = %8.8x, length = %8.8x\n",
- busnr, (int)(bus->busn_res.end - busnr));
+ len += sysfs_emit_at(buf, len,
+ "start = %8.8x, length = %8.8x\n",
+ busnr, (int)(bus->busn_res.end - busnr));
- return out - buf;
+ return len;
}
static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
--
2.31.1
next prev parent reply other threads:[~2021-05-18 3:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 3:40 [PATCH v3 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Krzysztof Wilczyński
2021-05-18 3:40 ` [PATCH v3 02/14] PCI/AER: " Krzysztof Wilczyński
2021-05-18 3:40 ` [PATCH v3 03/14] PCI: " Krzysztof Wilczyński
2021-05-24 21:14 ` Bjorn Helgaas
2021-05-24 21:19 ` Bjorn Helgaas
2021-05-25 10:32 ` Krzysztof Wilczyński
2021-05-25 16:07 ` Logan Gunthorpe
2021-05-18 3:40 ` [PATCH v3 04/14] PCI/MSI: " Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 05/14] PCI/IOV: " Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 06/14] PCI/P2PDMA: " Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 07/14] PCI/ASPM: " Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 08/14] PCI: switchtec: " Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 09/14] PCI: rpadlpar: " Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 10/14] PCI: hotplug: " Krzysztof Wilczyński
2021-05-18 3:41 ` Krzysztof Wilczyński [this message]
2021-05-18 3:41 ` [PATCH v3 12/14] PCI: Fix trailing newline handling of resource_alignment_param Krzysztof Wilczyński
2021-05-21 15:14 ` Krzysztof Wilczyński
2021-05-21 15:34 ` Logan Gunthorpe
2021-05-21 17:19 ` Greg Kroah-Hartman
2021-05-25 10:29 ` Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 13/14] PCI/sysfs: Add missing trailing newline to devspec_show() Krzysztof Wilczyński
2021-05-18 3:41 ` [PATCH v3 14/14] PCI/sysfs: Only show value when driver_override is not NULL Krzysztof Wilczyński
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210518034109.158450-11-kw@linux.com \
--to=kw@linux.com \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=joe@perches.com \
--cc=kurt.schwemmer@microsemi.com \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=mpe@ellerman.id.au \
--cc=oohall@gmail.com \
--cc=paulus@samba.org \
--cc=ruscur@russell.cc \
--cc=tyreld@linux.ibm.com \
--cc=vidyas@nvidia.com \
--cc=wangxiongfeng2@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox