in rio.c [1900:1961]
int rio_register_scan(int mport_id, struct rio_scan *scan_ops)
{
struct rio_mport *port;
struct rio_scan_node *scan;
int rc = 0;
pr_debug("RIO: %s for mport_id=%d\n", __func__, mport_id);
if ((mport_id != RIO_MPORT_ANY && mport_id >= RIO_MAX_MPORTS) ||
!scan_ops)
return -EINVAL;
mutex_lock(&rio_mport_list_lock);
/*
* Check if there is another enumerator already registered for
* the same mport ID (including RIO_MPORT_ANY). Multiple enumerators
* for the same mport ID are not supported.
*/
list_for_each_entry(scan, &rio_scans, node) {
if (scan->mport_id == mport_id) {
rc = -EBUSY;
goto err_out;
}
}
/*
* Allocate and initialize new scan registration node.
*/
scan = kzalloc(sizeof(*scan), GFP_KERNEL);
if (!scan) {
rc = -ENOMEM;
goto err_out;
}
scan->mport_id = mport_id;
scan->ops = scan_ops;
/*
* Traverse the list of registered mports to attach this new scan.
*
* The new scan with matching mport ID overrides any previously attached
* scan assuming that old scan (if any) is the default one (based on the
* enumerator registration check above).
* If the new scan is the global one, it will be attached only to mports
* that do not have their own individual operations already attached.
*/
list_for_each_entry(port, &rio_mports, node) {
if (port->id == mport_id) {
port->nscan = scan_ops;
break;
} else if (mport_id == RIO_MPORT_ANY && !port->nscan)
port->nscan = scan_ops;
}
list_add_tail(&scan->node, &rio_scans);
err_out:
mutex_unlock(&rio_mport_list_lock);
return rc;
}