From nobody Mon Apr 6 21:55:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23C8CC54EE9 for ; Fri, 16 Sep 2022 15:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbiIPPlq (ORCPT ); Fri, 16 Sep 2022 11:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbiIPPlZ (ORCPT ); Fri, 16 Sep 2022 11:41:25 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B657FAF0F0 for ; Fri, 16 Sep 2022 08:41:23 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id dv25so50230810ejb.12 for ; Fri, 16 Sep 2022 08:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=sFmKzGr7/jgOrZ/KXcj+36r+yAiKgKvBcXidghY+S9k=; b=sbTCQRmEL2RUqCAmHX8cej9pw5rDERUBY6tTHP2RTYESizXMbBTbevCdadgIPREtjA +pJDKu8kAKKiAZu8ht5/LcnHNNIFUdSJ6VscgAOPKpnCGMAt9vlGiOkAHjbb0aNSKDyB IWYfOrQ5CvAEW+V3Kw0pNMwvZMqwMJk8Ukn9ADzhMGal4vOs/WxcVlnggqQ8AnlrrPrB RfXZbLNrPQ+zSjm8O4U+GIqTxec3b87u0tS8PoUVESXteiJdhtLg5N4+KsEvXHVC0B9c M2SnEVa4dBbwp42bDBmxHVQMzHoJ+r5mHY05MF8K20NXawyjim+Kj0VJa8VaeVwCRi2X PPRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=sFmKzGr7/jgOrZ/KXcj+36r+yAiKgKvBcXidghY+S9k=; b=Et5aZ5C1GaVmka1sQOqxGagnCBq5zLigZRWMu9biKoy6CxQWrV1yOWf/pHJB5F3dkt +MA33gKvHrfjJW6j/fl17RbmEFze9nFdzU/rvlUIU8cqDwuB6r9613PWYoPtAwaQ2ngl UZYfcXerGOzI4Ykx4jNDB60aIKGWNxk/FarHxcsUMq1F5FZeUNTDVpc/FgQ5O29YiKvh 3OfMZ/3ed+cQIgrsPZYjLDYPV4s+ldp18gLSf3k7CZpPStwiMUb5R409cWmuw8UC+B5o +sD3oxOuIxr0Jpnv2nBbsc03RZaOBmlYKfIpcvLqdxbXgAtXHwDi98pSwxMSgFiAbxjV nuoA== X-Gm-Message-State: ACrzQf0MkWICMR45oa8QZZh3TNj3c0jlzcG9QxdK7KfDHOf+mEWxc+4z qBYqYolV/D5pVgZqM2/LhcNvkA== X-Google-Smtp-Source: AMsMyM73lBlgJT0MQvP+sfcKbhxdgA2Bdis/UhYlASU9T8QM0NoBdLbaaTlpq5vjRFzASdl5bDwLJg== X-Received: by 2002:a17:907:3e12:b0:780:523b:d9cf with SMTP id hp18-20020a1709073e1200b00780523bd9cfmr4031323ejc.326.1663342882273; Fri, 16 Sep 2022 08:41:22 -0700 (PDT) Received: from hackbox.lan ([94.52.112.99]) by smtp.gmail.com with ESMTPSA id e10-20020a1709062c0a00b0073d638a7a89sm10567707ejh.99.2022.09.16.08.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 08:41:21 -0700 (PDT) From: Abel Vesa To: Srinivas Kandagatla , Amol Maheshwari , Ekansh Gupta , Bharath Kumar , Himateja Reddy , Anirudh Raghavendra Cc: Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, Linux Kernel Mailing List Subject: [PATCH v4 5/9] misc: fastrpc: Rework fastrpc_req_munmap Date: Fri, 16 Sep 2022 18:40:58 +0300 Message-Id: <20220916154102.1768088-6-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916154102.1768088-1-abel.vesa@linaro.org> References: <20220916154102.1768088-1-abel.vesa@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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: Srinivas Kandagatla Signed-off-by: Abel Vesa --- drivers/misc/fastrpc.c | 47 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 0d9f1eb9a0ed..a1e916902deb 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1630,30 +1630,14 @@ static int fastrpc_get_dsp_info(struct fastrpc_user= *fl, char __user *argp) return 0; } =20 -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] =3D { [0] =3D { 0 } }; - struct fastrpc_buf *buf =3D NULL, *iter, *b; struct fastrpc_munmap_req_msg req_msg; struct device *dev =3D fl->sctx->dev; int err; u32 sc; =20 - spin_lock(&fl->lock); - list_for_each_entry_safe(iter, b, &fl->mmaps, node) { - if ((iter->raddr =3D=3D req->vaddrout) && (iter->size =3D=3D req->size))= { - buf =3D iter; - break; - } - } - spin_unlock(&fl->lock); - - if (!buf) { - dev_err(dev, "mmap not in list\n"); - return -EINVAL; - } - req_msg.pgid =3D fl->tgid; req_msg.size =3D buf->size; req_msg.vaddr =3D buf->raddr; @@ -1679,12 +1663,29 @@ static int fastrpc_req_munmap_impl(struct fastrpc_u= ser *fl, =20 static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) { + struct fastrpc_buf *buf =3D NULL, *iter, *b; struct fastrpc_req_munmap req; + struct device *dev =3D fl->sctx->dev; =20 if (copy_from_user(&req, argp, sizeof(req))) return -EFAULT; =20 - return fastrpc_req_munmap_impl(fl, &req); + spin_lock(&fl->lock); + list_for_each_entry_safe(iter, b, &fl->mmaps, node) { + if ((iter->raddr =3D=3D req.vaddrout) && (iter->size =3D=3D req.size)) { + buf =3D 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); } =20 static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) @@ -1693,7 +1694,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, = char __user *argp) struct fastrpc_buf *buf =3D 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 =3D fl->sctx->dev; @@ -1755,11 +1755,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl,= char __user *argp) spin_unlock(&fl->lock); =20 if (copy_to_user((void __user *)argp, &req, sizeof(req))) { - /* unmap the memory and release the buffer */ - req_unmap.vaddrout =3D buf->raddr; - req_unmap.size =3D buf->size; - fastrpc_req_munmap_impl(fl, &req_unmap); - return -EFAULT; + err =3D -EFAULT; + goto err_assign; } =20 dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", @@ -1767,6 +1764,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, = char __user *argp) =20 return 0; =20 +err_assign: + fastrpc_req_munmap_impl(fl, buf); err_invoke: fastrpc_buf_free(buf); =20 --=20 2.34.1