From 72fd1fd6698970a60ecc4961e2f865eae64461a7 Mon Sep 17 00:00:00 2001 From: cenhuilin Date: Wed, 17 Jul 2024 10:38:43 +0800 Subject: [PATCH] lspci: Fix filter support (-s/-d) for subtrees in tree mode (-t) --- ...er-support-for-subtrees-in-tree-mode.patch | 208 ++++++++++++++++++ pciutils.spec | 6 +- 2 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 6002-lspci-Fix-filter-support-for-subtrees-in-tree-mode.patch diff --git a/6002-lspci-Fix-filter-support-for-subtrees-in-tree-mode.patch b/6002-lspci-Fix-filter-support-for-subtrees-in-tree-mode.patch new file mode 100644 index 0000000..3b6e51c --- /dev/null +++ b/6002-lspci-Fix-filter-support-for-subtrees-in-tree-mode.patch @@ -0,0 +1,208 @@ +From 82dfc66797637859ca86b45b6b6007dd7c06a226 Mon Sep 17 00:00:00 2001 +From: Pali Rohár +Date: Tue, 4 Jun 2024 16:31:22 +0800 +Subject: [PATCH] [PATCH] lspci: Fix filter support (-s/-d) for subtrees in tree mode (-t) + +--- + ls-tree.c | 127 +++++++++++++++++++++++++++++++++++++++--------------- + 1 file changed, 93 insertions(+), 34 deletions(-) + +diff --git a/ls-tree.c b/ls-tree.c +index aeb4087..2726ad4 100644 +--- a/ls-tree.c ++++ b/ls-tree.c +@@ -153,7 +153,7 @@ print_it(char *line, char *p) + *p = ' '; + } + +-static void show_tree_bridge(struct bridge *, char *, char *); ++static void show_tree_bridge(struct pci_filter *filter, struct bridge *, char *, char *); + + #define LINE_BUF_SIZE 1024 + +@@ -181,7 +181,7 @@ tree_printf(char *line, char *p, char *fmt, ...) + } + + static void +-show_tree_dev(struct device *d, char *line, char *p) ++show_tree_dev(struct pci_filter *filter, struct device *d, char *line, char *p) + { + struct pci_dev *q = d->dev; + struct bridge *b; +@@ -195,7 +195,7 @@ show_tree_dev(struct device *d, char *line, char *p) + p = tree_printf(line, p, "-[%02x]-", b->secondary); + else + p = tree_printf(line, p, "-[%02x-%02x]-", b->secondary, b->subordinate); +- show_tree_bridge(b, line, p); ++ show_tree_bridge(filter, b, line, p); + return; + } + if (verbose) +@@ -206,53 +206,127 @@ show_tree_dev(struct device *d, char *line, char *p) + print_it(line, p); + } + ++static int ++check_bus_filter(struct pci_filter *filter, struct bus *b); ++ ++static int ++check_dev_filter(struct pci_filter *filter, struct device *d) ++{ ++ struct bridge *br; ++ struct bus *b; ++ ++ if (!filter) ++ return 1; ++ ++ if (pci_filter_match(filter, d->dev)) ++ return 1; ++ ++ for (br = &host_bridge; br; br = br->chain) ++ if (br->br_dev == d) ++ { ++ for (b = br->first_bus; b; b = b->sibling) ++ if (check_bus_filter(filter, b)) ++ return 1; ++ break; ++ } ++ ++ return 0; ++} ++ ++static int ++check_bus_filter(struct pci_filter *filter, struct bus *b) ++{ ++ struct device *d; ++ ++ if (!filter) ++ return 1; ++ ++ for (d = b->first_dev; d; d = d->bus_next) ++ if (check_dev_filter(filter, d)) ++ return 1; ++ ++ return 0; ++} ++ + static void +-show_tree_bus(struct bus *b, char *line, char *p) ++show_tree_bus(struct pci_filter *filter, struct bus *b, char *line, char *p) + { + if (!b->first_dev) + print_it(line, p); + else if (!b->first_dev->bus_next) + { +- p = tree_printf(line, p, "--"); +- show_tree_dev(b->first_dev, line, p); ++ if (check_dev_filter(filter, b->first_dev)) ++ { ++ p = tree_printf(line, p, "--"); ++ show_tree_dev(filter, b->first_dev, line, p); ++ } ++ else ++ print_it(line, p); + } + else + { ++ int empty = 1; + struct device *d = b->first_dev; + while (d->bus_next) + { +- char *p2 = tree_printf(line, p, "+-"); +- show_tree_dev(d, line, p2); ++ if (check_dev_filter(filter, d)) ++ { ++ char *p2 = tree_printf(line, p, "+-"); ++ show_tree_dev(filter, d, line, p2); ++ empty = 0; ++ } + d = d->bus_next; + } +- p = tree_printf(line, p, "\\-"); +- show_tree_dev(d, line, p); ++ if (check_dev_filter(filter, d)) ++ { ++ p = tree_printf(line, p, "\\-"); ++ show_tree_dev(filter, d, line, p); ++ empty = 0; ++ } ++ if (empty) ++ print_it(line, p); + } + } + + static void +-show_tree_bridge(struct bridge *b, char *line, char *p) ++show_tree_bridge(struct pci_filter *filter, struct bridge *b, char *line, char *p) + { + *p++ = '-'; + if (!b->first_bus->sibling) + { +- if (b == &host_bridge) +- p = tree_printf(line, p, "[%04x:%02x]-", b->domain, b->first_bus->number); +- show_tree_bus(b->first_bus, line, p); ++ if (check_bus_filter(filter, b->first_bus)) ++ { ++ if (b == &host_bridge) ++ p = tree_printf(line, p, "[%04x:%02x]-", b->domain, b->first_bus->number); ++ show_tree_bus(filter, b->first_bus, line, p); ++ } ++ else ++ print_it(line, p); + } + else + { ++ int empty = 1; + struct bus *u = b->first_bus; + char *k; + + while (u->sibling) + { +- k = tree_printf(line, p, "+-[%04x:%02x]-", u->domain, u->number); +- show_tree_bus(u, line, k); ++ if (check_bus_filter(filter, u)) ++ { ++ k = tree_printf(line, p, "+-[%04x:%02x]-", u->domain, u->number); ++ show_tree_bus(filter, u, line, k); ++ empty = 0; ++ } + u = u->sibling; + } +- k = tree_printf(line, p, "\\-[%04x:%02x]-", u->domain, u->number); +- show_tree_bus(u, line, k); ++ if (check_bus_filter(filter, u)) ++ { ++ k = tree_printf(line, p, "\\-[%04x:%02x]-", u->domain, u->number); ++ show_tree_bus(filter, u, line, k); ++ empty = 0; ++ } ++ if (empty) ++ print_it(line, p); + } + } + +@@ -260,20 +334,5 @@ void + show_forest(struct pci_filter *filter) + { + char line[LINE_BUF_SIZE]; +- if (filter == NULL) +- show_tree_bridge(&host_bridge, line, line); +- else +- { +- struct bridge *b; +- for (b=&host_bridge; b; b=b->chain) +- { +- if (b->br_dev && pci_filter_match(filter, b->br_dev->dev)) +- { +- struct pci_dev *d = b->br_dev->dev; +- char *p = line; +- p = tree_printf(line, p, "%04x:%02x:", d->domain_16, d->bus); +- show_tree_dev(b->br_dev, line, p); +- } +- } +- } ++ show_tree_bridge(filter, &host_bridge, line, line); + } +-- +2.33.0 + diff --git a/pciutils.spec b/pciutils.spec index bd5d44d..004e3a1 100644 --- a/pciutils.spec +++ b/pciutils.spec @@ -1,6 +1,6 @@ Name: pciutils Version: 3.6.4 -Release: 4 +Release: 5 Summary: PCI bus related utilities License: GPLv2+ URL: http://atrey.karlin.mff.cuni.cz/~mj/pciutils.shtml @@ -25,6 +25,7 @@ Patch6000: 6000-pciutils-2.2.1-idpath.patch #add support for directory with another pci.ids, rejected by upstream, rhbz#195327 Patch6001: 6001-pciutils-dir-d.patch +Patch6002: 6002-lspci-Fix-filter-support-for-subtrees-in-tree-mode.patch %description The PCI Utilities are a collection of programs for inspecting and manipulating configuration @@ -112,6 +113,9 @@ rm -rf $RPM_BUILD_ROOT/usr/share/hwdata/pci.ids* rm -rf $RPM_BUILD_ROOT %changelog +* Tue Jun 04 2024 cenhuilin - 3.6.4-5 +- lspci: Fix filter support (-s/-d) for subtrees in tree mode (-t) + * Tue Feb 9 2021 Zhiqiang Liu - 3.6.4-4 - solve i686 dependency problem and set release num to 4 for CI -- Gitee