Skip to content

Commit 72fa6f7

Browse files
abelvesagregkh
authored andcommitted
misc: fastrpc: Rework fastrpc_req_munmap
Move the lookup of the munmap request to the fastrpc_req_munmap and pass on only the buf to the lower level fastrpc_req_munmap_impl. That way we can use the lower level fastrpc_req_munmap_impl on error path in fastrpc_req_mmap to free the buf without searching for the munmap request it belongs to. Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Abel Vesa <abel.vesa@linaro.org> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20221125071405.148786-7-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 334f1a1 commit 72fa6f7

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

drivers/misc/fastrpc.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,30 +1627,14 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp)
16271627
return 0;
16281628
}
16291629

1630-
static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
1631-
struct fastrpc_req_munmap *req)
1630+
static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf)
16321631
{
16331632
struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
1634-
struct fastrpc_buf *buf = NULL, *iter, *b;
16351633
struct fastrpc_munmap_req_msg req_msg;
16361634
struct device *dev = fl->sctx->dev;
16371635
int err;
16381636
u32 sc;
16391637

1640-
spin_lock(&fl->lock);
1641-
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
1642-
if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) {
1643-
buf = iter;
1644-
break;
1645-
}
1646-
}
1647-
spin_unlock(&fl->lock);
1648-
1649-
if (!buf) {
1650-
dev_err(dev, "mmap not in list\n");
1651-
return -EINVAL;
1652-
}
1653-
16541638
req_msg.pgid = fl->tgid;
16551639
req_msg.size = buf->size;
16561640
req_msg.vaddr = buf->raddr;
@@ -1676,12 +1660,29 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
16761660

16771661
static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
16781662
{
1663+
struct fastrpc_buf *buf = NULL, *iter, *b;
16791664
struct fastrpc_req_munmap req;
1665+
struct device *dev = fl->sctx->dev;
16801666

16811667
if (copy_from_user(&req, argp, sizeof(req)))
16821668
return -EFAULT;
16831669

1684-
return fastrpc_req_munmap_impl(fl, &req);
1670+
spin_lock(&fl->lock);
1671+
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
1672+
if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
1673+
buf = iter;
1674+
break;
1675+
}
1676+
}
1677+
spin_unlock(&fl->lock);
1678+
1679+
if (!buf) {
1680+
dev_err(dev, "mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n",
1681+
req.vaddrout, req.size);
1682+
return -EINVAL;
1683+
}
1684+
1685+
return fastrpc_req_munmap_impl(fl, buf);
16851686
}
16861687

16871688
static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
@@ -1690,7 +1691,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
16901691
struct fastrpc_buf *buf = NULL;
16911692
struct fastrpc_mmap_req_msg req_msg;
16921693
struct fastrpc_mmap_rsp_msg rsp_msg;
1693-
struct fastrpc_req_munmap req_unmap;
16941694
struct fastrpc_phy_page pages;
16951695
struct fastrpc_req_mmap req;
16961696
struct device *dev = fl->sctx->dev;
@@ -1752,18 +1752,17 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
17521752
spin_unlock(&fl->lock);
17531753

17541754
if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
1755-
/* unmap the memory and release the buffer */
1756-
req_unmap.vaddrout = buf->raddr;
1757-
req_unmap.size = buf->size;
1758-
fastrpc_req_munmap_impl(fl, &req_unmap);
1759-
return -EFAULT;
1755+
err = -EFAULT;
1756+
goto err_assign;
17601757
}
17611758

17621759
dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
17631760
buf->raddr, buf->size);
17641761

17651762
return 0;
17661763

1764+
err_assign:
1765+
fastrpc_req_munmap_impl(fl, buf);
17671766
err_invoke:
17681767
fastrpc_buf_free(buf);
17691768

0 commit comments

Comments
 (0)