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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 7DD4BC433DB for ; Tue, 16 Mar 2021 00:34:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51DEA64EE2 for ; Tue, 16 Mar 2021 00:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbhCPAeX (ORCPT ); Mon, 15 Mar 2021 20:34:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:56558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230319AbhCPAeD (ORCPT ); Mon, 15 Mar 2021 20:34:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 25B3564EE2; Tue, 16 Mar 2021 00:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615854842; bh=DwO2abTrTPCBV+RWz5NIUo7YvPd35VK+3GPjS72Pk2c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GGGl+0vdncBll66DBxDxVWfhi8VZEKl2Hsx6U1GEcS/g+imWRE8u5iSCvACHvy8K3 +y4W/0cBVg8kM4IBqSvqtDYwTpwT9hMeFvWxRdod8HA0MwV93WoMWIDTeKlu5uc6jC IpyqIwqfQT67QKOIe+Kb4bHcKYnI2WU1Y5yUWDMXazEBd2ctHQiNnjoSB5vxEg4ucU 13ece8s49dFXct+CynmfjXr/xJwCc1lrDzIzAsXMLNn9jeCcNGFJIFIjYY0nS7Gwya a+4AoIPMv/GSTQ+4UwYMbaLqR5dF4ytYnIe4jVMbpIq/g1/SFC0FIBDXF1U/RJjwZ7 RN+U+EsMNNarg== Date: Tue, 16 Mar 2021 08:33:57 +0800 From: Peter Chen To: Sanket Parmar Cc: Pawel Laszczak , "a-govindraju@ti.com" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Rahul Kumar , "gregkh@linuxfoundation.org" , "kishon@ti.com" Subject: Re: [PATCH 2/2] usb: cdns3: Optimize DMA request buffer allocation Message-ID: <20210316003357.GC15335@b29397-desktop> References: <1615267180-9289-1-git-send-email-sparmar@cadence.com> <1615267180-9289-2-git-send-email-sparmar@cadence.com> <20210314051048.GA30122@b29397-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On 21-03-15 15:51:04, Sanket Parmar wrote: > > > + > > > priv_req->flags |= REQUEST_UNALIGNED; > > > trace_cdns3_prepare_aligned_request(priv_req); > > > > > > @@ -3088,11 +3113,11 @@ static void cdns3_gadget_exit(struct cdns > > *cdns) > > > struct cdns3_aligned_buf *buf; > > > > > > buf = cdns3_next_align_buf(&priv_dev->aligned_buf_list); > > > - dma_free_coherent(priv_dev->sysdev, buf->size, > > > - buf->buf, > > > - buf->dma); > > > + dma_unmap_single(priv_dev->sysdev, buf->dma, buf->size, > > > + buf->dir); > > > > It only needs to DMA unmap after DMA has completed, this buf will not be > > used, otherwise, the kfree below will cause issue. > > This part is not clear. Aligned DMA buffer is allocated and mapped in cdns3_prepare_aligned_request_buf() > and put into aligned_buf_list. While unloading the gadget, We need to undo the same if aligned_buf_list is not > empty. Am I missing something here? My point is this unmap operation is useless since there is no user for aligned buf, and it calls kfree afterwards. You could also keep it as it has no harm. > > Also, I will post v2 of this patch which uses dma_*_noncoherent APIs suggested by Christoph Hellwig. -- Thanks, Peter Chen