From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66103481FC7; Tue, 25 Aug 2026 13:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666125; cv=none; b=SH8HRSbuztGF3+665lfg8cCUbOzluFyBwo/f/7FnL3YDKapuP25xOHJBpFCk+E10+X0BJRpsR1mZBR2SMUswvTV6e/zuIGwDkMX11he7d1A5Q3CuRNKzbsWLuzPdShU+L24C0fm9Im066EnbRJYeR65TbQx1Yputs5cVsg3kxBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666125; c=relaxed/simple; bh=AF/P4cUsTtD/bGZS/YZi+Gdhjtislfa/SxjcVnNYp/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gta78UTzzRx3NiBUpdnsOo3xstF+z+Sz1nF4imCjBcvT2+i3UQAefi2IH2Q6PG92SsCqjq0iRUToRKZ6jmDgn3EFW5qnjKW06ohebrNVSoqre7ysf0lsdN1Q3AMgxbkAhinQNGhP9HPB82Kralrt/4M04vHmX5bhNtva1eZG/ts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xq5sKyyR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xq5sKyyR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B73B91F000E9; Tue, 25 Aug 2026 13:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787666124; bh=w7oME5B5DEOzoGl09HMcGX8LYJwoi9w28c1ExsmYQ9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xq5sKyyRKdKHDivyOsaL0m7lH5qPJn56h8M6tdirY8Ud+6OG5gHyvdnT+0Rp1GJXg l8vcEhpEK/elfG2UkXO1Ktfn+Q63/oCGyGgrjD9cI2M1Tw5iBnaEtws96rSv2F0l9f 9KIZL1thg4FEama3MNqGwJYMiQHTB957fqw2vw1k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Abel Vesa , Srinivas Kandagatla , Sasha Levin Subject: [PATCH 5.15 13/76] misc: fastrpc: Rework fastrpc_req_munmap Date: Tue, 25 Aug 2026 15:26:06 +0200 Message-ID: <20260825132542.054384883@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260825132541.568214149@linuxfoundation.org> References: <20260825132541.568214149@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Abel Vesa [ Upstream commit 72fa6f7820c4cf96c5f7aabc4e54bdf52d1e2ac2 ] 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 Signed-off-by: Abel Vesa Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20221125071405.148786-7-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman Stable-dep-of: 6102ceb4eab8 ("misc: fastrpc: Remove buffer from list prior to unmap operation") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/misc/fastrpc.c | 52 +++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1389,30 +1389,14 @@ static int fastrpc_invoke(struct fastrpc return err; } -static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, - struct fastrpc_req_munmap *req) +static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; - struct fastrpc_buf *buf = NULL, *iter, *b; struct fastrpc_munmap_req_msg req_msg; struct device *dev = fl->sctx->dev; int err; 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.size = buf->size; req_msg.vaddr = buf->raddr; @@ -1438,12 +1422,29 @@ static int fastrpc_req_munmap_impl(struc 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 device *dev = fl->sctx->dev; if (copy_from_user(&req, argp, sizeof(req))) 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) @@ -1452,7 +1453,6 @@ static int fastrpc_req_mmap(struct fastr struct fastrpc_buf *buf = NULL; struct fastrpc_mmap_req_msg req_msg; struct fastrpc_mmap_rsp_msg rsp_msg; - struct fastrpc_req_munmap req_unmap; struct fastrpc_phy_page pages; struct fastrpc_req_mmap req; struct device *dev = fl->sctx->dev; @@ -1500,7 +1500,8 @@ static int fastrpc_req_mmap(struct fastr &args[0]); if (err) { dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size); - goto err_invoke; + fastrpc_buf_free(buf); + return err; } /* update the buffer to be able to deallocate the memory on the DSP */ @@ -1514,11 +1515,8 @@ static int fastrpc_req_mmap(struct fastr spin_unlock(&fl->lock); if (copy_to_user((void __user *)argp, &req, sizeof(req))) { - /* unmap the memory and release the buffer */ - req_unmap.vaddrout = buf->raddr; - req_unmap.size = buf->size; - fastrpc_req_munmap_impl(fl, &req_unmap); - return -EFAULT; + err = -EFAULT; + goto err_assign; } dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", @@ -1526,8 +1524,8 @@ static int fastrpc_req_mmap(struct fastr return 0; -err_invoke: - fastrpc_buf_free(buf); +err_assign: + fastrpc_req_munmap_impl(fl, buf); return err; }