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 2/4] libpci: proc: Implement support for PCI_FILL_DRIVER
Date: Fri, 21 Jan 2022 15:03:49 +0100 [thread overview]
Message-ID: <20220121140351.27382-3-pali@kernel.org> (raw)
In-Reply-To: <20220121140351.27382-1-pali@kernel.org>
File /proc/bus/pci/devices contains optional driver name in the last 18th field.
---
lib/proc.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/lib/proc.c b/lib/proc.c
index cb9d08d17768..9b33863e69e6 100644
--- a/lib/proc.c
+++ b/lib/proc.c
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
@@ -69,9 +70,11 @@ proc_scan(struct pci_access *a)
{
struct pci_dev *d = pci_alloc_dev(a);
unsigned int dfn, vend, cnt, known;
+ char *driver;
+ int offset;
#define F " " PCIADDR_T_FMT
- cnt = sscanf(buf, "%x %x %x" F F F F F F F F F F F F F F,
+ cnt = sscanf(buf, "%x %x %x" F F F F F F F F F F F F F F "%n",
&dfn,
&vend,
&d->irq,
@@ -88,7 +91,8 @@ proc_scan(struct pci_access *a)
&d->size[3],
&d->size[4],
&d->size[5],
- &d->rom_size);
+ &d->rom_size,
+ &offset);
#undef F
if (cnt != 9 && cnt != 10 && cnt != 17)
a->error("proc: parse error (read only %d items)", cnt);
@@ -106,6 +110,20 @@ proc_scan(struct pci_access *a)
if (cnt >= 17)
known |= PCI_FILL_SIZES;
}
+ if (cnt >= 17)
+ {
+ while (buf[offset] && isspace(buf[offset]))
+ ++offset;
+ driver = &buf[offset];
+ while (buf[offset] && !isspace(buf[offset]))
+ ++offset;
+ buf[offset] = '\0';
+ if (driver[0])
+ {
+ pci_set_property(d, PCI_FILL_DRIVER, driver);
+ known |= PCI_FILL_DRIVER;
+ }
+ }
d->known_fields = known;
pci_link_dev(a, d);
}
--
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 ` Pali Rohár [this message]
2022-01-21 14:03 ` [PATCH pciutils 3/4] libpci: sysfs: Implement support for PCI_FILL_DRIVER Pali Rohár
2022-01-21 14:03 ` [PATCH pciutils 4/4] lspci: Replace find_driver() via libpci PCI_FILL_DRIVER Pali Rohár
2022-01-21 14:31 ` [PATCH pciutils 0/4] Support for PCI_FILL_DRIVER 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-3-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).