From patchwork Fri Sep 9 13:39:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 604247 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 15E77C6FA8E for ; Fri, 9 Sep 2022 13:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231435AbiIINlK (ORCPT ); Fri, 9 Sep 2022 09:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231400AbiIINkx (ORCPT ); Fri, 9 Sep 2022 09:40:53 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86CD9C52B for ; Fri, 9 Sep 2022 06:40:47 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id bz13so2828444wrb.2 for ; Fri, 09 Sep 2022 06:40:47 -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=KYXZxCPEEzXZVYVtbKeh9iOI/0iNF7jMlyDi7PazfWw=; b=NG8OO8VYsIkIEX9jsan04pkN+uruji+xvFNe1EZj9LiqJkBdzEsU1zHKLnyAL6Wnc5 C9d/xqE/+lSEmewmhXfdWaemk6hmaxhaiWv7+HrotzMPqZoVV8OrZJMEuo6ggg3bbfb/ PXzXqdiLKiyT/TspdEY+52tqilCxMjtR8wW2QIGjHch+vAAcFrYmUlthBoLv0CFgvD+R JnlfvqLdFEnTsffdQBDBLP+H0ISNZzCzPBznmx3lUgI+Nu52ksZBxGyMVu8XuafirTt6 umwm0w6fe+XbyUkfNZ9G31VKT8gcQJYFOXwej0oNYx0iqRcdVJlrZqtJePcA/M73AoI+ FyaA== 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=KYXZxCPEEzXZVYVtbKeh9iOI/0iNF7jMlyDi7PazfWw=; b=JkV2sgUG/wYrnAHr3HNhngckEaXEQEoueXf2jw5ZvCkiHrTAO3dww6mklcn+XBbJaz +Sz0ZJx2x8uw8EzTLJH3nCDU6iv0GTB56aOlOmWnCnlg1J5LPxAHk/vtixm/Sa+a0cNb BV6Pj5nY87FRZ8UEzkm/GiaZBXy+HonYSF5zRvKpzVhuteIXaQrB0F4MoEnXSjgfNXM/ aL42/nTfKGZkyxQBAulYhYiYpBSr//RLuO1nn6SgDBcN0l0sN/VMwGbeQwBQcqNO5uoR L6v/MW3wdYb19j0RqHF6dbWbNXf1R8OD3ta6MJdgql9nk4nUv/2HZuleJxGu+9Y38ndk 7tjQ== X-Gm-Message-State: ACgBeo3BXw8HDQwa8w2N5RAPc2cx/Lf7sZvmP84Y7GcNNLicUWVW9jsn kOmbQks+gF49hRbmbSHke9eBAw== X-Google-Smtp-Source: AA6agR7yY48kOVOUM3zFozgeXPJwhDsPZUtSAYxv4j9vHZkNRuEqHrO1lOlGi7a2vAg5WlbUq6t2kw== X-Received: by 2002:adf:f98b:0:b0:22a:2946:d98f with SMTP id f11-20020adff98b000000b0022a2946d98fmr6203707wrr.636.1662730847301; Fri, 09 Sep 2022 06:40:47 -0700 (PDT) Received: from hackbox.lan ([94.52.112.99]) by smtp.gmail.com with ESMTPSA id q20-20020a1cf314000000b003a604a29a34sm660622wmq.35.2022.09.09.06.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 06:40:46 -0700 (PDT) From: Abel Vesa To: Srinivas Kandagatla , Amol Maheshwari , Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Ekansh Gupta , Bharath Kumar , Himateja Reddy , Anirudh Raghavendra Cc: Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, Linux Kernel Mailing List , devicetree@vger.kernel.org Subject: [PATCH v3 06/10] misc: fastrpc: Rework fastrpc_req_munmap Date: Fri, 9 Sep 2022 16:39:34 +0300 Message-Id: <20220909133938.3518520-7-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909133938.3518520-1-abel.vesa@linaro.org> References: <20220909133938.3518520-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 8bc9cf5305c4..1f6d63bf637d 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; } -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; @@ -1679,12 +1663,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) @@ -1693,7 +1694,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; @@ -1755,11 +1755,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", @@ -1767,6 +1764,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) return 0; +err_assign: + fastrpc_req_munmap_impl(fl, buf); err_invoke: fastrpc_buf_free(buf);