Message ID | 20241210-pci-epc-core_fix-v3-2-4d86dd573e4b@quicinc.com (mailing list archive) |
---|---|
State | Accepted |
Commit | e0be8511ff50bec4927ec9bc27bf0a0eea5e8f63 |
Delegated to: | Bjorn Helgaas |
Headers | show |
Series | PCI: endpoint: fix bug for 2 APIs and simplify 1 API | expand |
On Tue, Dec 10, 2024 at 10:00:19PM +0800, Zijun Hu wrote: > From: Zijun Hu <quic_zijuhu@quicinc.com> > > Simplify pci_epc_get() implementation by API class_find_device_by_name(). > > Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/pci/endpoint/pci-epc-core.c | 21 ++++++--------------- > 1 file changed, 6 insertions(+), 15 deletions(-) > > diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c > index 71b6d100056e54438d0554f7ee82aaa64e0debb5..eb02d477bc7ca43a91b8a4a13c6ce96dab0b02fd 100644 > --- a/drivers/pci/endpoint/pci-epc-core.c > +++ b/drivers/pci/endpoint/pci-epc-core.c > @@ -60,26 +60,17 @@ struct pci_epc *pci_epc_get(const char *epc_name) > int ret = -EINVAL; > struct pci_epc *epc; > struct device *dev; > - struct class_dev_iter iter; > > - class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); > - while ((dev = class_dev_iter_next(&iter))) { > - if (strcmp(epc_name, dev_name(dev))) > - continue; > + dev = class_find_device_by_name(&pci_epc_class, epc_name); > + if (!dev) > + goto err; > > - epc = to_pci_epc(dev); > - if (!try_module_get(epc->ops->owner)) { > - ret = -EINVAL; > - goto err; > - } > - > - class_dev_iter_exit(&iter); > - get_device(&epc->dev); > + epc = to_pci_epc(dev); > + if (try_module_get(epc->ops->owner)) > return epc; > - } > > err: > - class_dev_iter_exit(&iter); > + put_device(dev); > return ERR_PTR(ret); > } > EXPORT_SYMBOL_GPL(pci_epc_get); > > -- > 2.34.1 >
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 71b6d100056e54438d0554f7ee82aaa64e0debb5..eb02d477bc7ca43a91b8a4a13c6ce96dab0b02fd 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -60,26 +60,17 @@ struct pci_epc *pci_epc_get(const char *epc_name) int ret = -EINVAL; struct pci_epc *epc; struct device *dev; - struct class_dev_iter iter; - class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); - while ((dev = class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) - continue; + dev = class_find_device_by_name(&pci_epc_class, epc_name); + if (!dev) + goto err; - epc = to_pci_epc(dev); - if (!try_module_get(epc->ops->owner)) { - ret = -EINVAL; - goto err; - } - - class_dev_iter_exit(&iter); - get_device(&epc->dev); + epc = to_pci_epc(dev); + if (try_module_get(epc->ops->owner)) return epc; - } err: - class_dev_iter_exit(&iter); + put_device(dev); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(pci_epc_get);