Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp9244945rwb; Thu, 24 Nov 2022 09:55:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ai1aDz5VoGQ2p/iSUkPjLXRNM3VCf76nIRKx0mSxqqDdKReQ6xIRP3oKQCFYl0yjZgH3f X-Received: by 2002:a05:6402:2929:b0:469:b603:ca21 with SMTP id ee41-20020a056402292900b00469b603ca21mr15519913edb.350.1669312523507; Thu, 24 Nov 2022 09:55:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669312523; cv=none; d=google.com; s=arc-20160816; b=u11YRi9HdOgolpZEOZMDiwOfvejDK87QFZUWKD0jUFzu1mqVvYVvWtkYF0y43L3xYw oj0dZ8HWwP3+AXiaBe+MD7+4Vx4GNe5cJdg/YAQpQ9bWuCuRlBvPLvikq0nv8R40T4LR z6LF99ZzFux7xYMw4JCIq9kbTd8L9qIzcH+V+pBymxw6hZPAZKJdqflWFitquq+3G2mn XNdJkQRoOvWSdtnW/OgJpc/NZ8RWBvImWqeOWdYBxkZSDLEZPiEIhA9y0y8kdZO1bS0Z TeyIDiHTtZzLkm/CH8xbaPZkQPnIeYv/UB6MkBWX0b4hcWvfezroHb3bKrnoXebEHfuR c6fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EGKfeLLXR8UXYClXrSFQFEuyRrCPr0drWE3Ez3BPlNU=; b=D+kjCQ9ELBGg0XXAswN7qPMFCTh4wiHXmE/Rhmbc0OOxMHYPxkUiQmpdzZ5YBQA/1E hHSYUevXGvhV5wtbe63UFcPqCPn7QMkCI/a7jVtQv+H0t3QY9NP9o+OO2HVS9wSrQP9T lWXfi4nhpAiKTcZfXglYHiLSyd3uZDP3JltQiv93gAd14CluN7Ke6ZtXFrfTGHlpdOHU tbHo2bB9MILfF+6mIRA70KGOBlkolJs5vktX4PyOe41krjnbktUg8JLLNHcm1EMzuMC/ 2KuK6AkdV2sIS+z55GyxyjOZv70VATebg/DijGw01iUiADwsKs9jRfmMrEuGzNrmigPv 5YAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vGbQnE5r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020a05640208d600b00461e122a4e4si1469312edz.314.2022.11.24.09.55.02; Thu, 24 Nov 2022 09:55:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vGbQnE5r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbiKXRwG (ORCPT + 86 others); Thu, 24 Nov 2022 12:52:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbiKXRvw (ORCPT ); Thu, 24 Nov 2022 12:51:52 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9146D1400F0 for ; Thu, 24 Nov 2022 09:51:47 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id 83-20020a1c0256000000b003d03017c6efso3765479wmc.4 for ; Thu, 24 Nov 2022 09:51:47 -0800 (PST) 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 :message-id:reply-to; bh=EGKfeLLXR8UXYClXrSFQFEuyRrCPr0drWE3Ez3BPlNU=; b=vGbQnE5rTF9zbT/k+8m87lu/6wkEriSHS8n2R84eGdUHEZ0ndOYQmmQ90Sd5j3DGFL Fb0U3vQyj/67eq8zLfpRjWJL2yFIrblLs3tn01mpxydkycvxSJb1tNkmLucVlY5gIdkX 4XzE17beahHVapYTDcqubUM5daz691L4dWq/6+I8Yk9hpj01qmStMPcr9Jr0Pl7Tut81 DFYK5cUGSdhYjJGCWnblp9qY794rcXcMkYYI21tcYPdDlFAlmD0FBZOyVZEmJR+uNd75 i0uVZRbDhBvMVEUHfk5dgwG7LkfPuoBNflPWZNMM/LIZ5zzhlbowFMXgxHcHFrCt5gkb /Tsg== 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:message-id:reply-to; bh=EGKfeLLXR8UXYClXrSFQFEuyRrCPr0drWE3Ez3BPlNU=; b=wOu9AS5xctD6H/PCU7bdnbJOkv+A9xUTR+6NskAPlDSndWgVkkA1bV3cWRonOPVg1x GW2qbS0gr2CRP+sw4wMazOcdVTemon2wFqDltAEHhhmP9pd1sH1+AUKpuJqrbcuZwpWa CKqa/xesG89pT79Umo7pKEvZSo/fuidpWWY5UR2mPxC/AS4VKzGjto5MlDkyvGWT86e9 JHCn5xIMTND7SwNGBJVozh2YVjVsNvfu0xJxhqx38CrsEDGv0qa0PISVZB7Z+QcBt1wZ Y3T5V/t6xy1ewlYWpYeADEP3cWze5Rz+pEjfKD61Iaer992oVoH4ormSIZwU3aCt97Pf wNqA== X-Gm-Message-State: ANoB5pn4BAg4QAB/QeQ46A8mJI5xboLaCgRA7VgIkbF/yBdfvYQ+gOQh GJeLyqfhCH+lZBECqkpBmUUV+Q== X-Received: by 2002:a05:600c:602a:b0:3c6:c05a:a50e with SMTP id az42-20020a05600c602a00b003c6c05aa50emr23904939wmb.81.1669312306091; Thu, 24 Nov 2022 09:51:46 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id bi8-20020a05600c3d8800b003c701c12a17sm6394192wmb.12.2022.11.24.09.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 09:51:45 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Abel Vesa , Srinivas Kandagatla Subject: [PATCH 07/11] misc: fastrpc: Rework fastrpc_req_munmap Date: Thu, 24 Nov 2022 17:51:21 +0000 Message-Id: <20221124175125.418702-8-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124175125.418702-1-srinivas.kandagatla@linaro.org> References: <20221124175125.418702-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Abel Vesa 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. Signed-off-by: Abel Vesa Co-developed-by: Srinivas Kandagatla Signed-off-by: Srinivas Kandagatla --- 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 b1e16bd56c6b..9a373fcb4ba0 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1633,30 +1633,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; @@ -1682,12 +1666,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) @@ -1696,7 +1697,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; @@ -1758,11 +1758,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", @@ -1770,6 +1767,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); -- 2.25.1