cdx: Introduce lock to protect controller ops
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration. Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com> Link: https://lore.kernel.org/r/20231017160505.10640-3-abhijit.gangurde@amd.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
54b406e10f
commit
f0af816834
1 changed files with 12 additions and 0 deletions
|
@ -72,6 +72,8 @@
|
||||||
|
|
||||||
/* IDA for CDX controllers registered with the CDX bus */
|
/* IDA for CDX controllers registered with the CDX bus */
|
||||||
static DEFINE_IDA(cdx_controller_ida);
|
static DEFINE_IDA(cdx_controller_ida);
|
||||||
|
/* Lock to protect controller ops */
|
||||||
|
static DEFINE_MUTEX(cdx_controller_lock);
|
||||||
|
|
||||||
static char *compat_node_name = "xlnx,versal-net-cdx";
|
static char *compat_node_name = "xlnx,versal-net-cdx";
|
||||||
|
|
||||||
|
@ -396,6 +398,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
|
||||||
if (!val)
|
if (!val)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
mutex_lock(&cdx_controller_lock);
|
||||||
|
|
||||||
/* Unregister all the devices on the bus */
|
/* Unregister all the devices on the bus */
|
||||||
cdx_unregister_devices(&cdx_bus_type);
|
cdx_unregister_devices(&cdx_bus_type);
|
||||||
|
|
||||||
|
@ -415,6 +419,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
|
||||||
put_device(&pd->dev);
|
put_device(&pd->dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&cdx_controller_lock);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
static BUS_ATTR_WO(rescan);
|
static BUS_ATTR_WO(rescan);
|
||||||
|
@ -538,12 +544,14 @@ int cdx_register_controller(struct cdx_controller *cdx)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_lock(&cdx_controller_lock);
|
||||||
cdx->id = ret;
|
cdx->id = ret;
|
||||||
|
|
||||||
/* Scan all the devices */
|
/* Scan all the devices */
|
||||||
if (cdx->ops->scan)
|
if (cdx->ops->scan)
|
||||||
cdx->ops->scan(cdx);
|
cdx->ops->scan(cdx);
|
||||||
cdx->controller_registered = true;
|
cdx->controller_registered = true;
|
||||||
|
mutex_unlock(&cdx_controller_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -554,9 +562,13 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
|
||||||
if (cdx->id >= MAX_CDX_CONTROLLERS)
|
if (cdx->id >= MAX_CDX_CONTROLLERS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
mutex_lock(&cdx_controller_lock);
|
||||||
|
|
||||||
cdx->controller_registered = false;
|
cdx->controller_registered = false;
|
||||||
device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
|
device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
|
||||||
ida_free(&cdx_controller_ida, cdx->id);
|
ida_free(&cdx_controller_ida, cdx->id);
|
||||||
|
|
||||||
|
mutex_unlock(&cdx_controller_lock);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(cdx_unregister_controller);
|
EXPORT_SYMBOL_GPL(cdx_unregister_controller);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue