From: "Pali Rohár" <pali@kernel.org>
To: "Martin Mares" <mj@ucw.cz>, "Bjorn Helgaas" <helgaas@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Matthew Wilcox" <willy@infradead.org>,
linux-pci@vger.kernel.org
Subject: [PATCH pciutils 4/4] lspci: Replace find_driver() via libpci PCI_FILL_DRIVER
Date: Fri, 21 Jan 2022 15:03:51 +0100 [thread overview]
Message-ID: <20220121140351.27382-5-pali@kernel.org> (raw)
In-Reply-To: <20220121140351.27382-1-pali@kernel.org>
And implement this show_kernel() and show_kernel_machine() for all
platforms.
---
ls-kernel.c | 56 +++++++++++++++--------------------------------------
1 file changed, 16 insertions(+), 40 deletions(-)
diff --git a/ls-kernel.c b/ls-kernel.c
index 2284b4625b12..3c484af7a9e0 100644
--- a/ls-kernel.c
+++ b/ls-kernel.c
@@ -212,40 +212,6 @@ show_kernel_cleanup(void)
#endif
-#define DRIVER_BUF_SIZE 1024
-
-static char *
-find_driver(struct device *d, char *buf)
-{
- struct pci_dev *dev = d->dev;
- char name[1024], *drv, *base;
- int n;
-
- if (dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
- return NULL;
-
- base = pci_get_param(dev->access, "sysfs.path");
- if (!base || !base[0])
- return NULL;
-
- n = snprintf(name, sizeof(name), "%s/devices/%04x:%02x:%02x.%d/driver",
- base, dev->domain, dev->bus, dev->dev, dev->func);
- if (n < 0 || n >= (int)sizeof(name))
- die("show_driver: sysfs device name too long, why?");
-
- n = readlink(name, buf, DRIVER_BUF_SIZE);
- if (n < 0)
- return NULL;
- if (n >= DRIVER_BUF_SIZE)
- return "<name-too-long>";
- buf[n] = 0;
-
- if (drv = strrchr(buf, '/'))
- return drv+1;
- else
- return buf;
-}
-
static const char *
next_module_filtered(struct device *d)
{
@@ -268,10 +234,10 @@ next_module_filtered(struct device *d)
void
show_kernel(struct device *d)
{
- char buf[DRIVER_BUF_SIZE];
const char *driver, *module;
- if (driver = find_driver(d, buf))
+ pci_fill_info(d->dev, PCI_FILL_DRIVER);
+ if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER))
printf("\tKernel driver in use: %s\n", driver);
if (!show_kernel_init())
@@ -287,10 +253,10 @@ show_kernel(struct device *d)
void
show_kernel_machine(struct device *d)
{
- char buf[DRIVER_BUF_SIZE];
const char *driver, *module;
- if (driver = find_driver(d, buf))
+ pci_fill_info(d->dev, PCI_FILL_DRIVER);
+ if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER))
printf("Driver:\t%s\n", driver);
if (!show_kernel_init())
@@ -303,13 +269,23 @@ show_kernel_machine(struct device *d)
#else
void
-show_kernel(struct device *d UNUSED)
+show_kernel(struct device *d)
{
+ const char *driver;
+
+ pci_fill_info(d->dev, PCI_FILL_DRIVER);
+ if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER))
+ printf("\tDriver in use: %s\n", driver);
}
void
-show_kernel_machine(struct device *d UNUSED)
+show_kernel_machine(struct device *d)
{
+ const char *driver;
+
+ pci_fill_info(d->dev, PCI_FILL_DRIVER);
+ if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER))
+ printf("Driver:\t%s\n", driver);
}
void
--
2.20.1
next prev parent reply other threads:[~2022-01-21 14:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-21 14:03 [PATCH pciutils 0/4] Support for PCI_FILL_DRIVER Pali Rohár
2022-01-21 14:03 ` [PATCH pciutils 1/4] libpci: Define new string property PCI_FILL_DRIVER Pali Rohár
2022-01-21 14:03 ` [PATCH pciutils 2/4] libpci: proc: Implement support for PCI_FILL_DRIVER Pali Rohár
2022-01-21 14:03 ` [PATCH pciutils 3/4] libpci: sysfs: " Pali Rohár
2022-01-21 14:03 ` Pali Rohár [this message]
2022-01-21 14:31 ` [PATCH pciutils 0/4] Support " Martin Mareš
2022-01-21 14:40 ` Pali Rohár
2022-01-21 14:46 ` Martin Mareš
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=20220121140351.27382-5-pali@kernel.org \
--to=pali@kernel.org \
--cc=helgaas@kernel.org \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=mj@ucw.cz \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).