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 DC8DD3B7B97 for ; Thu, 20 Aug 2026 19:36:30 +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=1787254592; cv=none; b=LR4g4D0ZVt/a2jrx6CvuCxPQ2F5AqhCwxpi8HUmVni8qEiSmU1szbMd4nFLwn2VGMctLqfQpt18fw3+S8ueQUVVpmQ0u4TByCp0rP5Rw76dV24NYcNhlsZI+7OO8aK35ATRm4NZsmyJfa6FzJqqPCB8y21auz0gAQ9gnxEiAxiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787254592; c=relaxed/simple; bh=fohymdYN7//vWPUjAdS6PipLbEkxP6fBQIamK2etMbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XLftQ0mYNHQoXvwWNtMBYVEfVVbmdtEqTcqIuG/fKSzejwjiEFgPY3u+lQhvzESC7qnFezreyrCz4YfMBmeDiW4dLZQB+F2fI8NUFCy698GLnRcM6uKDqBYhSeI8WDSeGK9zpX6eEwn8D/vJz9I+OBsJc8pjIG2ju51pAfg8YmY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BloA2Za/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BloA2Za/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E390D1F00A3A; Thu, 20 Aug 2026 19:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787254590; bh=JTb9wj/3dE0aW8SroUISk/qU+SDf5eVvtVTSICXwIZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BloA2Za/FS3WWZSkOMdwQhYya1u8Mxx1Vq16rYpEn3bDIvw7LE0JCJ3EHynT78jV+ GEzaN0MW8876DgBgzV6NxIt6Fkc6eU9MqncbkzObCHqJou7T8w68aXvqPQxfiBIN5B mNYcnls6WTiFS3LR8FoWJ8Zzs8IwqaCvo3E9RL1ws376+049dDSYg0LprVIBmrKbfV NwPI50giCgrDFv4yG+JvnOzetcivQpZ1A8q4wBrNiTvlbH+UI7k4F6SO/ZGMy7/icS wdDxWLtuqIJgdhOlM2SWUNFNXSqp+GcqBvLqsJD8Nd1q7OiPTfVIoQOCooQ3Z18Eqx zXAZQmgOfj+oQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Abel Vesa , Srinivas Kandagatla , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.15.y 2/3] misc: fastrpc: Rework fastrpc_req_munmap Date: Thu, 20 Aug 2026 15:36:25 -0400 Message-ID: <20260820193626.2274224-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260820193626.2274224-1-sashal@kernel.org> References: <2026081715-crucial-stammer-2659@gregkh> <20260820193626.2274224-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- drivers/misc/fastrpc.c | 52 ++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 5c90d965765d0..33b4d3bf54a8d 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1389,30 +1389,14 @@ static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) 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(struct fastrpc_user *fl, 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 fastrpc_user *fl, char __user *argp) 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 fastrpc_user *fl, char __user *argp) &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 fastrpc_user *fl, char __user *argp) 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 fastrpc_user *fl, char __user *argp) return 0; -err_invoke: - fastrpc_buf_free(buf); +err_assign: + fastrpc_req_munmap_impl(fl, buf); return err; } -- 2.53.0