diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 9dd079964729..bd694fb65b56 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1471,6 +1471,13 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, u32 sc; unsigned long flags; + if (!fl->cctx->remote_heap || + !fl->cctx->remote_heap->dma_addr || + !fl->cctx->remote_heap->size) { + err = -ENOMEM; + dev_dbg(fl->sctx->dev, "remote heap memory region is not added\n"); + return err; + } args = kzalloc_objs(*args, FASTRPC_CREATE_STATIC_PROCESS_NARGS); if (!args) return -ENOMEM; @@ -1506,14 +1513,6 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, spin_lock_irqsave(&cctx->lock, flags); if (!fl->cctx->audio_init_mem) { - if (!fl->cctx->remote_heap || - !fl->cctx->remote_heap->dma_addr || - !fl->cctx->remote_heap->size) { - spin_unlock_irqrestore(&cctx->lock, flags); - err = -ENOMEM; - goto err; - } - pages[0].addr = fl->cctx->remote_heap->dma_addr; pages[0].size = fl->cctx->remote_heap->size; fl->cctx->audio_init_mem = true; @@ -2155,17 +2154,14 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) if (copy_to_user((void __user *)argp, &req, sizeof(req))) { err = -EFAULT; - goto err_copy; + goto err_assign; } dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", buf->raddr, buf->size); return 0; -err_copy: - spin_lock(&fl->lock); - list_del(&buf->node); - spin_unlock(&fl->lock); + err_assign: fastrpc_req_munmap_impl(fl, buf); @@ -2569,6 +2565,15 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) err = of_reserved_mem_region_to_resource(rdev->of_node, 0, &res); if (!err) { + if (domain_id == ADSP_DOMAIN_ID) { + data->remote_heap = + kzalloc_obj(*data->remote_heap, GFP_KERNEL); + if (!data->remote_heap) + return -ENOMEM; + + data->remote_heap->dma_addr = res.start; + data->remote_heap->size = resource_size(&res); + } src_perms = BIT(QCOM_SCM_VMID_HLOS); err = qcom_scm_assign_mem(res.start, resource_size(&res), &src_perms, @@ -2576,16 +2581,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) if (err) goto err_free_data; } - - if (domain_id == ADSP_DOMAIN_ID) { - data->remote_heap = - kzalloc_obj(*data->remote_heap, GFP_KERNEL); - if (!data->remote_heap) - return -ENOMEM; - - data->remote_heap->dma_addr = res.start; - data->remote_heap->size = resource_size(&res); - } } secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain")); @@ -2698,7 +2693,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) cctx->remote_heap->size, &src_perms, &dst_perms, 1); if (!err) - fastrpc_buf_free(cctx->remote_heap); + kfree(cctx->remote_heap); } of_platform_depopulate(&rpdev->dev);