in rio_cm.c [1228:1272]
static int riocm_ch_bind(u16 ch_id, u8 mport_id, void *context)
{
struct rio_channel *ch = NULL;
struct cm_dev *cm;
int rc = -ENODEV;
riocm_debug(CHOP, "ch_%d to mport_%d", ch_id, mport_id);
/* Find matching cm_dev object */
down_read(&rdev_sem);
list_for_each_entry(cm, &cm_dev_list, list) {
if ((cm->mport->id == mport_id) &&
rio_mport_is_running(cm->mport)) {
rc = 0;
break;
}
}
if (rc)
goto exit;
ch = riocm_get_channel(ch_id);
if (!ch) {
rc = -EINVAL;
goto exit;
}
spin_lock_bh(&ch->lock);
if (ch->state != RIO_CM_IDLE) {
spin_unlock_bh(&ch->lock);
rc = -EINVAL;
goto err_put;
}
ch->cmdev = cm;
ch->loc_destid = cm->mport->host_deviceid;
ch->context = context;
ch->state = RIO_CM_CHAN_BOUND;
spin_unlock_bh(&ch->lock);
err_put:
riocm_put_channel(ch);
exit:
up_read(&rdev_sem);
return rc;
}