Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Abel Vesa and committed by
Greg Kroah-Hartman
72fa6f78 334f1a1c

+23 -24
+23 -24
drivers/misc/fastrpc.c
··· 1627 1627 return 0; 1628 1628 } 1629 1629 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) 1632 1631 { 1633 1632 struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; 1634 - struct fastrpc_buf *buf = NULL, *iter, *b; 1635 1633 struct fastrpc_munmap_req_msg req_msg; 1636 1634 struct device *dev = fl->sctx->dev; 1637 1635 int err; 1638 1636 u32 sc; 1639 - 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 1637 1654 1638 req_msg.pgid = fl->tgid; 1655 1639 req_msg.size = buf->size; ··· 1660 1676 1661 1677 static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) 1662 1678 { 1679 + struct fastrpc_buf *buf = NULL, *iter, *b; 1663 1680 struct fastrpc_req_munmap req; 1681 + struct device *dev = fl->sctx->dev; 1664 1682 1665 1683 if (copy_from_user(&req, argp, sizeof(req))) 1666 1684 return -EFAULT; 1667 1685 1668 - return fastrpc_req_munmap_impl(fl, &req); 1686 + spin_lock(&fl->lock); 1687 + list_for_each_entry_safe(iter, b, &fl->mmaps, node) { 1688 + if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) { 1689 + buf = iter; 1690 + break; 1691 + } 1692 + } 1693 + spin_unlock(&fl->lock); 1694 + 1695 + if (!buf) { 1696 + dev_err(dev, "mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n", 1697 + req.vaddrout, req.size); 1698 + return -EINVAL; 1699 + } 1700 + 1701 + return fastrpc_req_munmap_impl(fl, buf); 1669 1702 } 1670 1703 1671 1704 static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) ··· 1691 1690 struct fastrpc_buf *buf = NULL; 1692 1691 struct fastrpc_mmap_req_msg req_msg; 1693 1692 struct fastrpc_mmap_rsp_msg rsp_msg; 1694 - struct fastrpc_req_munmap req_unmap; 1695 1693 struct fastrpc_phy_page pages; 1696 1694 struct fastrpc_req_mmap req; 1697 1695 struct device *dev = fl->sctx->dev; ··· 1752 1752 spin_unlock(&fl->lock); 1753 1753 1754 1754 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; 1760 1757 } 1761 1758 1762 1759 dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", ··· 1761 1764 1762 1765 return 0; 1763 1766 1767 + err_assign: 1768 + fastrpc_req_munmap_impl(fl, buf); 1764 1769 err_invoke: 1765 1770 fastrpc_buf_free(buf); 1766 1771