From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20110C433E0 for ; Wed, 1 Jul 2020 06:10:07 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E55F82074D for ; Wed, 1 Jul 2020 06:10:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qsy1oTEz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E55F82074D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=driverdev-devel-bounces@linuxdriverproject.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 679F730197; Wed, 1 Jul 2020 06:10:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YM7kSADVy6rx; Wed, 1 Jul 2020 06:10:03 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id F36BF2FFF1; Wed, 1 Jul 2020 06:10:02 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 95A351BF83C for ; Wed, 1 Jul 2020 06:10:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 9283D8B86D for ; Wed, 1 Jul 2020 06:10:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3Fmnb1Bkbgvg for ; Wed, 1 Jul 2020 06:10:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by whitealder.osuosl.org (Postfix) with ESMTPS id B1ECE8B1C5 for ; Wed, 1 Jul 2020 06:10:00 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id o13so8210330pgf.0 for ; Tue, 30 Jun 2020 23:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iJXQLBehWwPwwPoGiInoAvr+iwWO0xFUwp5XsZYJ0Wc=; b=qsy1oTEzSRTnDgDlzAbsXmEbfOTK6Kgt+sy4W4NbwNJeT/VgP5zyHxXEAl7okwkCY2 4v9rfF40pxuxPrjHK1mS9QoJn1ALGVIAvsKF2QJmYXpMhmW3rJZ+4phopvzekJq4owgS xeBvwHnrtDk1EXUjR3/UrYnmOphRxpk9ApPK2VQbF8uBMhoWNv4oMTeHbNvhMvGbp2sI yKxXK3uXJeFpLmlS1zkUL9Con0gW7VAkjwFQqoPzftnGu6ZEmgeju4Lsw5HGK0y4FpPp NxxoYy0pjuSTDhiDzRmmmiEmOA/FO1R5T1fzd/RhDp8R/9HOJwGPmAGdI/nHr25jiquX gNkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iJXQLBehWwPwwPoGiInoAvr+iwWO0xFUwp5XsZYJ0Wc=; b=CC7zfJjprsbgbLU2g1i/ctE3bNyGNUauo9Mz4CRoH+QUoJTghmJ6xPhsl9AQtgB9uM U1P7aWwQD5Z6a49hmaq/oCeWBqPu+GmeOJp7u0nzGbw3rZ5yKpRAXwM2r4KNnClc8Jrt 9q94a1ACU45pvRs/9Iy15N2mIIR1iYGpkihrYeAcpgI6UrmQ1YDyxPWoh/YAAJPA7OdX OnK2Iz+7TkneBEyZFDObtnttzxtW1JSaSVnEPh8GJql/omCwXPITREdtzkbsjfFO0NP9 Jid3GI/KMzvCb2l2ZqbopYsiK+UfcPKi/5o0jxJdVzjoMp+b4zAM9UvgzrtVVMW5W9XV uyEg== X-Gm-Message-State: AOAM530/9RFYVWr1XoxUthIYgrzWwh6qMMteM3fTGeGa+zqOwVrEFzfv VL4yNXuZ7Yuq7dX6RCSdd14= X-Google-Smtp-Source: ABdhPJyAWnEZKEKAJ11azWAi7WrF/Rs8eY9d2O15O3QWBbIEB9lh8c4pvA0qM811KBZO3njehbGxGA== X-Received: by 2002:a63:5013:: with SMTP id e19mr18445859pgb.68.1593583800326; Tue, 30 Jun 2020 23:10:00 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC.domain.name ([122.171.42.200]) by smtp.gmail.com with ESMTPSA id 127sm4694073pgf.5.2020.06.30.23.09.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2020 23:09:59 -0700 (PDT) From: Souptick Joarder To: gregkh@linuxfoundation.org, jane.pnx9@gmail.com, daniel.m.jordan@oracle.com, simon@nikanor.nu, harshjain32@gmail.com, pakki001@umn.edu Subject: [PATCH v3 4/4] staging: kpc2000: kpc_dma: Remove additional goto statements Date: Wed, 1 Jul 2020 11:47:44 +0530 Message-Id: <1593584264-16982-5-git-send-email-jrdr.linux@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1593584264-16982-1-git-send-email-jrdr.linux@gmail.com> References: <1593584264-16982-1-git-send-email-jrdr.linux@gmail.com> X-BeenThere: driverdev-devel@linuxdriverproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, Bharath Vedartham , John Hubbard , linux-kernel@vger.kernel.org, Souptick Joarder , Dan Carpenter MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" As 3 goto level referring to same common code, those can be accomodated with a single goto level and renameing it to unpin_pages. Set the -ERRNO when returning partial mapped pages in more appropriate place. When dma_map_sg() failed, the previously allocated memory was not freed properly. This is corrected now. Signed-off-by: Souptick Joarder Cc: John Hubbard Cc: Bharath Vedartham Cc: Dan Carpenter --- drivers/staging/kpc2000/kpc_dma/fileops.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c index 8cd20ad..dd716edd 100644 --- a/drivers/staging/kpc2000/kpc_dma/fileops.c +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c @@ -35,7 +35,7 @@ static int kpc_dma_transfer(struct dev_private_data *priv, unsigned long iov_base, size_t iov_len) { unsigned int i = 0; - int rv = 0; + int rv = 0, nr_pages = 0; struct kpc_dma_device *ldev; struct aio_cb_data *acd; DECLARE_COMPLETION_ONSTACK(done); @@ -79,22 +79,27 @@ static int kpc_dma_transfer(struct dev_private_data *priv, rv = pin_user_pages(iov_base, acd->page_count, FOLL_TOUCH | FOLL_WRITE, acd->user_pages, NULL); mmap_read_unlock(current->mm); /* release the semaphore */ if (rv != acd->page_count) { + nr_pages = rv; + if (rv > 0) + rv = -EFAULT; + dev_err(&priv->ldev->pldev->dev, "Couldn't pin_user_pages (%d)\n", rv); - goto err_get_user_pages; + goto unpin_pages; } + nr_pages = acd->page_count; // Allocate and setup the sg_table (scatterlist entries) rv = sg_alloc_table_from_pages(&acd->sgt, acd->user_pages, acd->page_count, iov_base & (PAGE_SIZE - 1), iov_len, GFP_KERNEL); if (rv) { dev_err(&priv->ldev->pldev->dev, "Couldn't alloc sg_table (%d)\n", rv); - goto err_alloc_sg_table; + goto unpin_pages; } // Setup the DMA mapping for all the sg entries acd->mapped_entry_count = dma_map_sg(&ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, ldev->dir); if (acd->mapped_entry_count <= 0) { dev_err(&priv->ldev->pldev->dev, "Couldn't dma_map_sg (%d)\n", acd->mapped_entry_count); - goto err_dma_map_sg; + goto free_table; } // Calculate how many descriptors are actually needed for this transfer. @@ -186,16 +191,12 @@ static int kpc_dma_transfer(struct dev_private_data *priv, err_descr_too_many: unlock_engine(ldev); dma_unmap_sg(&ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, ldev->dir); + free_table: sg_free_table(&acd->sgt); - err_dma_map_sg: - err_alloc_sg_table: - unpin_user_pages(acd->user_pages, acd->page_count); - err_get_user_pages: - if (rv > 0) { - unpin_user_pages(acd->user_pages, rv); - rv = -EFAULT; - } + unpin_pages: + if (nr_pages > 0) + unpin_user_pages(acd->user_pages, nr_pages); kfree(acd->user_pages); err_alloc_userpages: kfree(acd); -- 1.9.1 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel