Пример #1
0
static int vocpcm_open(struct inode *inode, struct file *file)
{
    struct voc_rpc *voc_rpc = &the_voc_proc;
    struct voc_ctxt *ctxt = voc_minor_to_ctxt(MINOR(inode->i_rdev));
    int rc = 0;

    if (!ctxt) {
        pr_err("unknown voc misc %d\n", MINOR(inode->i_rdev));
        return -ENODEV;
    }

    mutex_lock(&voc_rpc->lock);
    if (voc_rpc->inited == 0) {
        voc_rpc->ept = create_rpc_connect(RPC_SND_PROG, RPC_SND_VERS,
                                          MSM_RPC_UNINTERRUPTIBLE |
                                          MSM_RPC_ENABLE_RECEIVE);
        if (IS_ERR(voc_rpc->ept)) {
            rc = PTR_ERR(voc_rpc->ept);
            voc_rpc->ept = NULL;
            pr_err("vocpcm: failed to connect snd svc\n");
            return rc;
        }

        voc_rpc->task = create_snd_rpc_kthread();
        if (IS_ERR(voc_rpc->task)) {
            rc = PTR_ERR(voc_rpc->task);
            voc_rpc->task = NULL;
            msm_rpc_close(voc_rpc->ept);
            voc_rpc->ept = NULL;
            return rc;
        }
        voc_rpc->inited = 1;
    }
    mutex_unlock(&voc_rpc->lock);

    mutex_lock(&ctxt->lock);
    if (ctxt->opened) {
        pr_err("vocpcm already opened.\n");
        rc = -EBUSY;
        goto err;
    }

    file->private_data = ctxt;
    ctxt->head = 0;
    ctxt->tail = 0;
    ctxt->client = 0;

    memset(ctxt->buf[0].data, 0, sizeof(ctxt->buf[0].data));
    memset(ctxt->buf[1].data, 0, sizeof(ctxt->buf[1].data));
    ctxt->buf[0].index = 0;
    ctxt->buf[1].index = 0;
    ctxt->opened = 1;
    ctxt->count = 0;
    ctxt->s_ptr = 0;
    ctxt->final_input = 0;

err:
    mutex_unlock(&ctxt->lock);
    return rc;
}
Пример #2
0
static int snd_open(struct inode *inode, struct file *file)
{
	struct snd_ctxt *snd = &the_snd;
	int rc = 0;

	mutex_lock(&snd->lock);
	if (snd->inited == 0) {
		snd->ept = create_rpc_connect(RPC_SND_PROG, RPC_SND_VERS,
					MSM_RPC_UNINTERRUPTIBLE |
					MSM_RPC_ENABLE_RECEIVE);
		if (IS_ERR(snd->ept)) {
			rc = PTR_ERR(snd->ept);
			snd->ept = NULL;
			pr_err("snd: failed to connect snd svc\n");
			goto err;
		}

		snd->task = create_snd_rpc_kthread();
		if (IS_ERR(snd->task)) {
			rc = PTR_ERR(snd->task);
			snd->task = NULL;
			msm_rpc_close(snd->ept);
			snd->ept = NULL;
			goto err;
		}
		snd->inited = 1;
	}

	if (snd->opened) {
		pr_err("snd already opened.\n");
		rc = -EBUSY;
		goto err;
	}

	file->private_data = snd;
	snd->opened = 1;
err:
	mutex_unlock(&snd->lock);
	return rc;
}