Skip to content

Commit e5c98e6

Browse files
xiaoguangwuwenlingz
authored andcommitted
DM USB: add usb_dev_path_cmp function for convenience
Comparing two USB devices' path is frequently used operation, abstract it as an seperated function for convenience. Tracked-On: #1893 Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Reviewed-by: Liang Yang <liang3.yang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 6c1ca13 commit e5c98e6

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

devicemodel/hw/pci/xhci.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,23 +542,13 @@ pci_xhci_get_native_port_index_by_path(struct pci_xhci_vdev *xdev,
542542
struct usb_devpath *path)
543543
{
544544
int i;
545-
struct usb_devpath *p;
546545

547546
assert(xdev);
548547
assert(path);
549548

550-
for (i = 0; i < XHCI_MAX_VIRT_PORTS; i++) {
551-
p = &xdev->native_ports[i].info.path;
552-
553-
if (p->bus != path->bus)
554-
continue;
555-
556-
if (p->depth != path->depth)
557-
continue;
558-
559-
if (memcmp(p->path, path->path, path->depth) == 0)
549+
for (i = 0; i < XHCI_MAX_VIRT_PORTS; i++)
550+
if (usb_dev_path_cmp(&xdev->native_ports[i].info.path, path))
560551
return i;
561-
}
562552
return -1;
563553
}
564554

devicemodel/hw/usb_core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ usb_dev_path(struct usb_devpath *path)
272272
return output;
273273
}
274274

275+
bool
276+
usb_dev_path_cmp(struct usb_devpath *p1, struct usb_devpath *p2)
277+
{
278+
if (!p1 || !p2)
279+
return false;
280+
281+
return (p1->bus == p2->bus && p1->depth == p2->depth &&
282+
memcmp(p1->path, p2->path, p1->depth) == 0);
283+
}
284+
275285
int
276286
usb_get_hub_port_num(struct usb_devpath *path)
277287
{

devicemodel/include/usb_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,5 @@ struct usb_data_xfer_block *usb_data_xfer_append(struct usb_data_xfer *xfer,
257257
int ccs);
258258
int usb_get_hub_port_num(struct usb_devpath *path);
259259
char *usb_dev_path(struct usb_devpath *path);
260+
bool usb_dev_path_cmp(struct usb_devpath *p1, struct usb_devpath *p2);
260261
#endif /* _USB_CORE_H_ */

0 commit comments

Comments
 (0)