Skip to content

Commit 13327ed

Browse files
abelvesagregkh
authored andcommitted
misc: fastrpc: Rework fastrpc_req_munmap
[ Upstream commit 72fa6f7 ] 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> Stable-dep-of: 6102ceb ("misc: fastrpc: Remove buffer from list prior to unmap operation") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 03a1225 commit 13327ed

1 file changed

Lines changed: 23 additions & 24 deletions

File tree

drivers/misc/fastrpc.c

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

1660-
static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
1661-
struct fastrpc_req_munmap *req)
1660+
static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf)
16621661
{
16631662
struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
1664-
struct fastrpc_buf *buf = NULL, *iter, *b;
16651663
struct fastrpc_munmap_req_msg req_msg;
16661664
struct device *dev = fl->sctx->dev;
16671665
int err;
16681666
u32 sc;
16691667

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 not in list\n");
1681-
return -EINVAL;
1682-
}
1683-
16841668
req_msg.pgid = fl->tgid;
16851669
req_msg.size = buf->size;
16861670
req_msg.vaddr = buf->raddr;
@@ -1706,12 +1690,29 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
17061690

17071691
static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
17081692
{
1693+
struct fastrpc_buf *buf = NULL, *iter, *b;
17091694
struct fastrpc_req_munmap req;
1695+
struct device *dev = fl->sctx->dev;
17101696

17111697
if (copy_from_user(&req, argp, sizeof(req)))
17121698
return -EFAULT;
17131699

1714-
return fastrpc_req_munmap_impl(fl, &req);
1700+
spin_lock(&fl->lock);
1701+
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
1702+
if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
1703+
buf = iter;
1704+
break;
1705+
}
1706+
}
1707+
spin_unlock(&fl->lock);
1708+
1709+
if (!buf) {
1710+
dev_err(dev, "mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n",
1711+
req.vaddrout, req.size);
1712+
return -EINVAL;
1713+
}
1714+
1715+
return fastrpc_req_munmap_impl(fl, buf);
17151716
}
17161717

17171718
static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
@@ -1720,7 +1721,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
17201721
struct fastrpc_buf *buf = NULL;
17211722
struct fastrpc_mmap_req_msg req_msg;
17221723
struct fastrpc_mmap_rsp_msg rsp_msg;
1723-
struct fastrpc_req_munmap req_unmap;
17241724
struct fastrpc_phy_page pages;
17251725
struct fastrpc_req_mmap req;
17261726
struct device *dev = fl->sctx->dev;
@@ -1782,18 +1782,17 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
17821782
spin_unlock(&fl->lock);
17831783

17841784
if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
1785-
/* unmap the memory and release the buffer */
1786-
req_unmap.vaddrout = buf->raddr;
1787-
req_unmap.size = buf->size;
1788-
fastrpc_req_munmap_impl(fl, &req_unmap);
1789-
return -EFAULT;
1785+
err = -EFAULT;
1786+
goto err_assign;
17901787
}
17911788

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

17951792
return 0;
17961793

1794+
err_assign:
1795+
fastrpc_req_munmap_impl(fl, buf);
17971796
err_invoke:
17981797
fastrpc_buf_free(buf);
17991798

0 commit comments

Comments
 (0)