Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp407414pxj; Fri, 11 Jun 2021 02:05:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOCNiClpFTKcX2imY6R02VXou5Ecf1XftpFeEZeh0nNZnYyNrxoHne+czilR8VgESfyerd X-Received: by 2002:a17:906:b0c8:: with SMTP id bk8mr2775176ejb.412.1623402307823; Fri, 11 Jun 2021 02:05:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623402307; cv=none; d=google.com; s=arc-20160816; b=WXhvEJTLhrE8Reb4Zk+hEHwH7bKwu8rvSKeb3DrTIRpGoEplMLPpHKP8MI7A6Ktq1I yDRQEJ1v4moloIPrBaXaCx+URCB3B9FwuLqQTKrSqbD2cjHU7ghRPodIhiGo7QhSKrjX ChHMn/vlwNFZ1t95pz+HPdpRU6g1xG/6A/rQcVLAJg22oBQronxggQaQB6kPuJyQoBJm te0mzkSHamsb9j8mCkFBrwTUB4+ZCH9umisTa1gGHmGJeVjkf+HC42vwJHsDjF1nVSSY 47F4N7/Yzu1ps29Un+OmirU8BZuXmH38k4L2399YVy5NO25+Y7bhnyZvfyi9xKSrESBa 4NJg== 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=8YCoCRqbOmEh51NxHoLmHsLlkKYsuBLx8KTpCpYe64Q=; b=IWYax4TGXNGxyiSlOHoesjsag5IH79cL/cPSfGxrmJY8D9UTaU4TL5Ow1UbKE+GSZh a1SshtRM6C1LEGEwKOqlfGRkv9aIwqtN/DKctKOFhJwmVa+XIGiBWwM08NdeXjAl42e3 XU8Urp1jDigUETK287Efgbv/Ael/O/N/AP8Q/2m8gH1yrsAa3iyxN8QC8XIbfnKL05OA 4rB4pFO3WqPE4wveqvXY/6Rqq3+KUQ25tBLIHAv9cf2dEu/TU7IN62xl5Azji6Q++hCA uYGiUjfU4GcY8eNUqdb/SifWzICDergPcERzY8rpB/OnRNUwf7iKhpV8jaK6ZQ8dj59Z 3gdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=U3+lXwYs; 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 k21si4363383edr.572.2021.06.11.02.04.44; Fri, 11 Jun 2021 02:05:07 -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=U3+lXwYs; 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 S231286AbhFKJFj (ORCPT + 99 others); Fri, 11 Jun 2021 05:05:39 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:33168 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbhFKJFj (ORCPT ); Fri, 11 Jun 2021 05:05:39 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E2A1721965; Fri, 11 Jun 2021 09:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623402220; 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=8YCoCRqbOmEh51NxHoLmHsLlkKYsuBLx8KTpCpYe64Q=; b=U3+lXwYsQKcVXRhEYlrT/1PslapKoSZDxIG6UFkzvOGaBPqSPcsUA5rsUolUm7ApEtU3lC vPDpUkuSaF4LHWAGoLoe60OGCmcfNb2HfSgsdWC8qWaUthQpJxAtmTcnQ3uhD48ahsflk2 xd980G9HVpeF3Tfyics6AL7nupc59DU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623402220; 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=8YCoCRqbOmEh51NxHoLmHsLlkKYsuBLx8KTpCpYe64Q=; b=JEZ3F72ca61RfxjewIcXDiRYEUocTp6PJ8smz1ouihGSJG5Fytoi9iQfnmw5G3NgiBPd86 jTFZi9mE9WC/WQCg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id D1063A3BB3; Fri, 11 Jun 2021 09:03:40 +0000 (UTC) From: Takashi Iwai To: Adrian Hunter Cc: Ulf Hansson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path Date: Fri, 11 Jun 2021 11:03:30 +0200 Message-Id: <20210611090330.13039-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. Signed-off-by: Takashi Iwai --- 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..5f467b98ca88 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->parent, 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