Skip to content

Commit e0be851

Browse files
zijun-hubjorn-helgaas
authored andcommitted
PCI: endpoint: Simplify pci_epc_get()
Simplify pci_epc_get() implementation by using class_find_device_by_name(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Zijun Hu <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Frank Li <[email protected]>
1 parent d492975 commit e0be851

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,17 @@ struct pci_epc *pci_epc_get(const char *epc_name)
6060
int ret = -EINVAL;
6161
struct pci_epc *epc;
6262
struct device *dev;
63-
struct class_dev_iter iter;
6463

65-
class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL);
66-
while ((dev = class_dev_iter_next(&iter))) {
67-
if (strcmp(epc_name, dev_name(dev)))
68-
continue;
64+
dev = class_find_device_by_name(&pci_epc_class, epc_name);
65+
if (!dev)
66+
goto err;
6967

70-
epc = to_pci_epc(dev);
71-
if (!try_module_get(epc->ops->owner)) {
72-
ret = -EINVAL;
73-
goto err;
74-
}
75-
76-
class_dev_iter_exit(&iter);
77-
get_device(&epc->dev);
68+
epc = to_pci_epc(dev);
69+
if (try_module_get(epc->ops->owner))
7870
return epc;
79-
}
8071

8172
err:
82-
class_dev_iter_exit(&iter);
73+
put_device(dev);
8374
return ERR_PTR(ret);
8475
}
8576
EXPORT_SYMBOL_GPL(pci_epc_get);

0 commit comments

Comments
 (0)