static int hsc_open()

in clients/hsi_char.c [589:631]


static int hsc_open(struct inode *inode, struct file *file)
{
	struct hsc_client_data *cl_data;
	struct hsc_channel *channel;
	int ret = 0;

	pr_debug("open, minor = %d\n", iminor(inode));

	cl_data = container_of(inode->i_cdev, struct hsc_client_data, cdev);
	mutex_lock(&cl_data->lock);
	channel = cl_data->channels + (iminor(inode) & HSC_CH_MASK);

	if (test_and_set_bit(HSC_CH_OPEN, &channel->flags)) {
		ret = -EBUSY;
		goto out;
	}
	/*
	 * Check if we have already claimed the port associated to the HSI
	 * client. If not then try to claim it, else increase its refcount
	 */
	if (cl_data->usecnt == 0) {
		ret = hsi_claim_port(cl_data->cl, 0);
		if (ret < 0)
			goto out;
		hsi_setup(cl_data->cl);
	}
	cl_data->usecnt++;

	ret = hsc_msgs_alloc(channel);
	if (ret < 0) {
		__hsc_port_release(cl_data);
		goto out;
	}

	file->private_data = channel;
	mutex_unlock(&cl_data->lock);

	return ret;
out:
	mutex_unlock(&cl_data->lock);

	return ret;
}