mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									334f1a1cbe
								
							
						
					
					
						commit
						72fa6f7820
					
				
					 1 changed files with 23 additions and 24 deletions
				
			
		| 
						 | 
					@ -1627,30 +1627,14 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp)
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
 | 
					static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf)
 | 
				
			||||||
				   struct fastrpc_req_munmap *req)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
 | 
						struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
 | 
				
			||||||
	struct fastrpc_buf *buf = NULL, *iter, *b;
 | 
					 | 
				
			||||||
	struct fastrpc_munmap_req_msg req_msg;
 | 
						struct fastrpc_munmap_req_msg req_msg;
 | 
				
			||||||
	struct device *dev = fl->sctx->dev;
 | 
						struct device *dev = fl->sctx->dev;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
	u32 sc;
 | 
						u32 sc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spin_lock(&fl->lock);
 | 
					 | 
				
			||||||
	list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
 | 
					 | 
				
			||||||
		if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) {
 | 
					 | 
				
			||||||
			buf = iter;
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	spin_unlock(&fl->lock);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!buf) {
 | 
					 | 
				
			||||||
		dev_err(dev, "mmap not in list\n");
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	req_msg.pgid = fl->tgid;
 | 
						req_msg.pgid = fl->tgid;
 | 
				
			||||||
	req_msg.size = buf->size;
 | 
						req_msg.size = buf->size;
 | 
				
			||||||
	req_msg.vaddr = buf->raddr;
 | 
						req_msg.vaddr = buf->raddr;
 | 
				
			||||||
| 
						 | 
					@ -1676,12 +1660,29 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
 | 
					static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct fastrpc_buf *buf = NULL, *iter, *b;
 | 
				
			||||||
	struct fastrpc_req_munmap req;
 | 
						struct fastrpc_req_munmap req;
 | 
				
			||||||
 | 
						struct device *dev = fl->sctx->dev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (copy_from_user(&req, argp, sizeof(req)))
 | 
						if (copy_from_user(&req, argp, sizeof(req)))
 | 
				
			||||||
		return -EFAULT;
 | 
							return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return fastrpc_req_munmap_impl(fl, &req);
 | 
						spin_lock(&fl->lock);
 | 
				
			||||||
 | 
						list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
 | 
				
			||||||
 | 
							if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
 | 
				
			||||||
 | 
								buf = iter;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						spin_unlock(&fl->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!buf) {
 | 
				
			||||||
 | 
							dev_err(dev, "mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n",
 | 
				
			||||||
 | 
								req.vaddrout, req.size);
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return fastrpc_req_munmap_impl(fl, buf);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 | 
					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)
 | 
				
			||||||
	struct fastrpc_buf *buf = NULL;
 | 
						struct fastrpc_buf *buf = NULL;
 | 
				
			||||||
	struct fastrpc_mmap_req_msg req_msg;
 | 
						struct fastrpc_mmap_req_msg req_msg;
 | 
				
			||||||
	struct fastrpc_mmap_rsp_msg rsp_msg;
 | 
						struct fastrpc_mmap_rsp_msg rsp_msg;
 | 
				
			||||||
	struct fastrpc_req_munmap req_unmap;
 | 
					 | 
				
			||||||
	struct fastrpc_phy_page pages;
 | 
						struct fastrpc_phy_page pages;
 | 
				
			||||||
	struct fastrpc_req_mmap req;
 | 
						struct fastrpc_req_mmap req;
 | 
				
			||||||
	struct device *dev = fl->sctx->dev;
 | 
						struct device *dev = fl->sctx->dev;
 | 
				
			||||||
| 
						 | 
					@ -1752,11 +1752,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 | 
				
			||||||
	spin_unlock(&fl->lock);
 | 
						spin_unlock(&fl->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
 | 
						if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
 | 
				
			||||||
		/* unmap the memory and release the buffer */
 | 
							err = -EFAULT;
 | 
				
			||||||
		req_unmap.vaddrout = buf->raddr;
 | 
							goto err_assign;
 | 
				
			||||||
		req_unmap.size = buf->size;
 | 
					 | 
				
			||||||
		fastrpc_req_munmap_impl(fl, &req_unmap);
 | 
					 | 
				
			||||||
		return -EFAULT;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
 | 
						dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
 | 
				
			||||||
| 
						 | 
					@ -1764,6 +1761,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_assign:
 | 
				
			||||||
 | 
						fastrpc_req_munmap_impl(fl, buf);
 | 
				
			||||||
err_invoke:
 | 
					err_invoke:
 | 
				
			||||||
	fastrpc_buf_free(buf);
 | 
						fastrpc_buf_free(buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue