Commit 07301c98 authored by Kishon Vijay Abraham I's avatar Kishon Vijay Abraham I Committed by Lorenzo Pieralisi

PCI: endpoint: Protect concurrent access to pci_epf_ops with mutex

Protect concurrent access to pci_epf_ops with a mutex.
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
parent 04e046ca
...@@ -35,7 +35,9 @@ void pci_epf_unbind(struct pci_epf *epf) ...@@ -35,7 +35,9 @@ void pci_epf_unbind(struct pci_epf *epf)
return; return;
} }
mutex_lock(&epf->lock);
epf->driver->ops->unbind(epf); epf->driver->ops->unbind(epf);
mutex_unlock(&epf->lock);
module_put(epf->driver->owner); module_put(epf->driver->owner);
} }
EXPORT_SYMBOL_GPL(pci_epf_unbind); EXPORT_SYMBOL_GPL(pci_epf_unbind);
...@@ -49,6 +51,8 @@ EXPORT_SYMBOL_GPL(pci_epf_unbind); ...@@ -49,6 +51,8 @@ EXPORT_SYMBOL_GPL(pci_epf_unbind);
*/ */
int pci_epf_bind(struct pci_epf *epf) int pci_epf_bind(struct pci_epf *epf)
{ {
int ret;
if (!epf->driver) { if (!epf->driver) {
dev_WARN(&epf->dev, "epf device not bound to driver\n"); dev_WARN(&epf->dev, "epf device not bound to driver\n");
return -EINVAL; return -EINVAL;
...@@ -57,7 +61,11 @@ int pci_epf_bind(struct pci_epf *epf) ...@@ -57,7 +61,11 @@ int pci_epf_bind(struct pci_epf *epf)
if (!try_module_get(epf->driver->owner)) if (!try_module_get(epf->driver->owner))
return -EAGAIN; return -EAGAIN;
return epf->driver->ops->bind(epf); mutex_lock(&epf->lock);
ret = epf->driver->ops->bind(epf);
mutex_unlock(&epf->lock);
return ret;
} }
EXPORT_SYMBOL_GPL(pci_epf_bind); EXPORT_SYMBOL_GPL(pci_epf_bind);
...@@ -252,6 +260,7 @@ struct pci_epf *pci_epf_create(const char *name) ...@@ -252,6 +260,7 @@ struct pci_epf *pci_epf_create(const char *name)
device_initialize(dev); device_initialize(dev);
dev->bus = &pci_epf_bus_type; dev->bus = &pci_epf_bus_type;
dev->type = &pci_epf_type; dev->type = &pci_epf_type;
mutex_init(&epf->lock);
ret = dev_set_name(dev, "%s", name); ret = dev_set_name(dev, "%s", name);
if (ret) { if (ret) {
......
...@@ -110,6 +110,7 @@ struct pci_epf_bar { ...@@ -110,6 +110,7 @@ struct pci_epf_bar {
* @driver: the EPF driver to which this EPF device is bound * @driver: the EPF driver to which this EPF device is bound
* @list: to add pci_epf as a list of PCI endpoint functions to pci_epc * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
* @nb: notifier block to notify EPF of any EPC events (like linkup) * @nb: notifier block to notify EPF of any EPC events (like linkup)
* @lock: mutex to protect pci_epf_ops
*/ */
struct pci_epf { struct pci_epf {
struct device dev; struct device dev;
...@@ -124,6 +125,8 @@ struct pci_epf { ...@@ -124,6 +125,8 @@ struct pci_epf {
struct pci_epf_driver *driver; struct pci_epf_driver *driver;
struct list_head list; struct list_head list;
struct notifier_block nb; struct notifier_block nb;
/* mutex to protect against concurrent access of pci_epf_ops */
struct mutex lock;
}; };
#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev) #define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment