From patchwork Fri Jan 29 09:45:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 8161511 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D78AB9F96D for ; Fri, 29 Jan 2016 09:50:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 064C220115 for ; Fri, 29 Jan 2016 09:50:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20D1C200C1 for ; Fri, 29 Jan 2016 09:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753441AbcA2JuO (ORCPT ); Fri, 29 Jan 2016 04:50:14 -0500 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:44284 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752271AbcA2JuN (ORCPT ); Fri, 29 Jan 2016 04:50:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=bjyoAlEWDcKAqc0D4BK8OybzwQjsJh4DXoO/SmbD3xw=; b=Cnl90vnxcFYdDDwxuPNSr3P8D3eRPEdzfehQ+lbdxFnzzI3StUpimEAD334JXERlaq56yqQeldR/Mkjoo06f5HCkFCHgNttQr//n9VmjhoH+l9wB1TllUfBRvJDyDmr/bihwX5tjWL/feYML4V+QXjbp5QNh5TCBfgTQOWoVVOI=; Received: from e0022681537dd.dyn.arm.linux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:42081 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aP5cD-0001kp-OR; Fri, 29 Jan 2016 09:45:17 +0000 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aP5cA-0001qG-EU; Fri, 29 Jan 2016 09:45:14 +0000 In-Reply-To: <20160129094324.GA20025@n2100.arm.linux.org.uk> References: <20160129094324.GA20025@n2100.arm.linux.org.uk> From: Russell King To: Ulf Hansson Cc: Gregory CLEMENT , linux-mmc@vger.kernel.org, Marcin Wojtas , Shawn Guo , Sascha Hauer Subject: [PATCH v4 17/25] mmc: sdhci: clean up host cookie handling MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Fri, 29 Jan 2016 09:45:14 +0000 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit d31911b9374a ("mmc: sdhci: fix dma memory leak in sdhci_pre_req()") added a complicated method to manage the DMA map state for the data transfer, but this complexity is not required. There are three states: * Unmapped * Mapped by sdhci_pre_req() * Mapped by sdhci_prepare_data() sdhci_prepare_data() needs to know when the data buffers have been successfully mapped by sdhci_pre_req(), and if so, there is no need to map them a second time. When we come to tear down the mapping, we want to know whether sdhci_post_req() will be called (which is determined by sdhci_pre_req() having been previously called) so that we can postpone the unmap operation. Hence, it makes sense to simply record when the successful DMA map happened (via COOKIE_PRE_MAPPED vs COOKIE_MAPPED) rather than having the complex mechanics involving COOKIE_MAPPED vs COOKIE_GIVEN. If a mapping is created by sdhci_prepare_data(), we must tear it down ourselves, without waiting for sdhci_post_req() (hence, the new COOKIE_MAPPED case). If the mapping is created by sdhci_pre_req() then sdhci_post_req() is responsible for tearing the mapping down. Signed-off-by: Russell King --- drivers/mmc/host/sdhci.c | 12 ++++++------ drivers/mmc/host/sdhci.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 3da2a0461e4b..a714c628394b 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -431,12 +431,12 @@ static int sdhci_pre_dma_transfer(struct sdhci_host *host, { int sg_count; - if (data->host_cookie == COOKIE_MAPPED) { - data->host_cookie = COOKIE_GIVEN; + /* + * If the data buffers are already mapped, return the previous + * dma_map_sg() result. + */ + if (data->host_cookie == COOKIE_PRE_MAPPED) return data->sg_count; - } - - WARN_ON(data->host_cookie == COOKIE_GIVEN); sg_count = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, data->flags & MMC_DATA_WRITE ? @@ -2084,7 +2084,7 @@ static void sdhci_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, mrq->data->host_cookie = COOKIE_UNMAPPED; if (host->flags & SDHCI_REQ_USE_DMA) - sdhci_pre_dma_transfer(host, mrq->data, COOKIE_MAPPED); + sdhci_pre_dma_transfer(host, mrq->data, COOKIE_PRE_MAPPED); } static void sdhci_card_event(struct mmc_host *mmc) diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 7654ae5d2b4e..19e9291e5074 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -316,8 +316,8 @@ struct sdhci_adma2_64_desc { enum sdhci_cookie { COOKIE_UNMAPPED, - COOKIE_MAPPED, - COOKIE_GIVEN, + COOKIE_PRE_MAPPED, /* mapped by sdhci_pre_req() */ + COOKIE_MAPPED, /* mapped by sdhci_prepare_data() */ }; struct sdhci_host {