Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp452427pxj; Fri, 11 Jun 2021 03:23:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjykATWcH5CsnBhPLI7sJXy9VDqQ3qUnqTS0bi9vts6O8E7WOBgHckfartQ6d0A/w5iYR3 X-Received: by 2002:a17:906:2988:: with SMTP id x8mr3054861eje.122.1623406998939; Fri, 11 Jun 2021 03:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623406998; cv=none; d=google.com; s=arc-20160816; b=y4GqU+pc1FVZIhmeirANh+MYGy0PkQtZe8PTkgfHofFY8765C5ZQ3JX100+u5yDzRB 0Oiw4L6BTOZfY/gpIUr2POi2o2MJJigekj3P/Mg4i9i+E4GS6LEUVnpDJKFKiu13kv4b ABG+7E9+L9tEGx9oEmmYpL6EhIahxsHkGIuyjRvto3rOQRAIt+phJZk3ktQrf8ZX4+m2 pUsyxZb4kh6YxRezI7zYHUvUOS+xzlZDgn8d39Km6Fbe6qUc4C+GuWCIpsxibrHH/7K7 h4VmtkV/1qJED/N75ULX3Y9PmHEAxlDw1AXn5rRTL98VCK2YWFptBJKpxfvcVs4eOjG2 NyPg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=EEVv8+Y68AKuFcnRR39WUeUcighivtR1a//+t2osEQQ=; b=H82SRlLVBKyaMWTktI0D08C2YbrbU7wkdKPb+spPmMklcGQzG+UxxitwvOqOGoED4I t/O8zEHavSGy8qSaZjpHgdPzw46SRdruaAiPZAhBEMLZOR9NMNErtq6F8rsRIUvex9Et b2z4D1f5HB7Q42M+RjUM/Eg6/YqxP4PBlkkxxyrQuQKnaU5D8ap1qpAh3/GF1rv7ZjNi v1yURJC8fY8XBIpio2IqOv8p7fhJb2g2uIz4uSdYynRwBkE5BVdHcjJQSWbXXCLpOofG PRKC48oHZgNNCNuxfNif5AVZiPRMD6h7yJfbmeQ575SUvI8vX3pGnRbtbKno4UEEY6lC 3+ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="jB/WKsg3"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z13si4435313edq.281.2021.06.11.03.22.56; Fri, 11 Jun 2021 03:23:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="jB/WKsg3"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhFKKVv (ORCPT + 99 others); Fri, 11 Jun 2021 06:21:51 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:59300 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbhFKKVt (ORCPT ); Fri, 11 Jun 2021 06:21:49 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 58A911FD6C; Fri, 11 Jun 2021 10:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623406791; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EEVv8+Y68AKuFcnRR39WUeUcighivtR1a//+t2osEQQ=; b=jB/WKsg3tkJNnhcuOxRbJRTWJRVVt8Norn4wRUbtQnh+EcuII3j3KwN/1afeJNOUOrzFwc CZDGIMOtD5xTvxc+i75dJwpt481GGMRGx5Ro4Mekh+NcMGH7niEV20Wwzu7OAc6YaXW5L5 fMDxL540q6wy22TOEzRBpLvk3TCA4Vo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623406791; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EEVv8+Y68AKuFcnRR39WUeUcighivtR1a//+t2osEQQ=; b=W0eCPVfLqLCax/n1FI+p7ycQseWODwo8MORQ8PEtlAcn1nE9if7x97JRpp28PKPOaiIasD 2kFwUEhzD3SSSoBA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 46B5EA3BAA; Fri, 11 Jun 2021 10:19:51 +0000 (UTC) From: Takashi Iwai To: Adrian Hunter Cc: Ulf Hansson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path Date: Fri, 11 Jun 2021 12:19:48 +0200 Message-Id: <20210611101948.18972-1-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When DMA-mapping of the bounce buffer fails, the driver tries to fall back, but it leaves the allocated host->bounce_buffer although its size is zero. Later on, the driver checks the use of bounce buffer with host->bounce_buffer pointer, and it tries to use the buffer incorrectly, resulting in Oops. This patch clears the release the unused buffer and clears the bounce_buffer pointer for addressing the problem. Acked-by: Adrian Hunter Signed-off-by: Takashi Iwai --- v1->v2: correct the device pointer to mmc_dev(mmc) drivers/mmc/host/sdhci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index bf238ade1602..c80bc6c4ebf3 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -4072,9 +4072,13 @@ static void sdhci_allocate_bounce_buffer(struct sdhci_host *host) bounce_size, DMA_BIDIRECTIONAL); ret = dma_mapping_error(mmc_dev(mmc), host->bounce_addr); - if (ret) + if (ret) { + devm_kfree(mmc_dev(mmc), host->bounce_buffer); + host->bounce_buffer = NULL; /* Again fall back to max_segs == 1 */ return; + } + host->bounce_buffer_size = bounce_size; /* Lie about this since we're bouncing */ -- 2.26.2