From patchwork Mon Aug 31 13:16:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 248741 Delivered-To: patches@linaro.org Received: by 2002:a17:906:6447:0:0:0:0 with SMTP id l7csp2693264ejn; Mon, 31 Aug 2020 06:16:44 -0700 (PDT) X-Received: by 2002:a05:651c:1291:: with SMTP id 17mr716828ljc.366.1598879803849; Mon, 31 Aug 2020 06:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598879803; cv=none; d=google.com; s=arc-20160816; b=R9qoZ4uz6vTqPaJDk66y4H6Gqje8dRNZSbb58WT/KQZMHayFrUJoYb+kRRRFh6pYKr Cnwd9ddOf3P6DWWsB0vRxz/QZjqW3b3lOpoj0Y38JAAACCZnpLCGQ/m5Ac7cPay9hyHB V6T2UUkqlU0OxUhM1FXpGx2WXGKatbYIjVpE0GeyU/aIwgRf+px+9d2ILEoPDCW1p5GM 3l3tKayaElUofwPg5f0S4tXipGCjm67PlVoj0NZE+5iAlO+k4j4g0DRn0MghMnrU9zQE 3yolzEreuV1EXdd0067UYoy6RhExEzVTDEzKKoZuAgR3w6GLovrRb+xPBlV2zsZOqq93 gXXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=UQoI1GeQhVK5+wMgW0TP/WghvzBAWuVFG8q6FGoAyEw=; b=SOhUfpekAdxKXLFx9OOzHwgTEPtV6xsmYRsclGcia+qU2MMTAp1hKmkxKhB2TeZGrZ Ece49MNiFbNITQQnrWRt0BNn9thg4jQnTbg0ntcscCzi97x26m7Ez7PYlE8M8SCvJQUa tnYBBjHmMzV6zp2b+f+0ckGZKXtYlyJw2jnYpGUj4fQXjkqnTglQafR67mVn2UNDAlaM MaUYavlFuDUG4pZ5k0i5FCBBHzdRnwFwFHtAVPIxrIWwtQNhHhgfz6zsdhKJhvkMOzRl CoW6goqBRVQ+inpmmcMkF0mdEypjhQ7OK1fCpyDzoRKySj198jMwCaEvREfgheuvsig0 RpaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mDVAQkQ4; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q13sor1437224lfb.31.2020.08.31.06.16.43 for (Google Transport Security); Mon, 31 Aug 2020 06:16:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mDVAQkQ4; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UQoI1GeQhVK5+wMgW0TP/WghvzBAWuVFG8q6FGoAyEw=; b=mDVAQkQ4nwJalyxEi62enizY/JY4FUg76of5iT2j26oB8IYHKuIH0RQKSkJMimjeYj 0S5G5EZYatzFkdiTnmlS8MwYw0MPgHU41vlt6+++tl0KCq/GGznPC/W9y65RmVXYTRc4 VDICi+t+zpxh+MpHqK+4I7aEZCf7KqDyrTQ+6+7BKTcoMbTatXvzKZ3CiEA7TX+PsaAr hqaIH3zCSVXnfdWcPx7ZICi+56VMHe/BOromwtM+N268RTyEgRFZaQXWHIs5sxx8WWgd qP1cecE9ppABFVqGBmxsEW3AFkH96rRNsGH3nbtQTSRgtztLSZANcdoU34bj7OnSMIQf cKwA== 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:mime-version :content-transfer-encoding; bh=UQoI1GeQhVK5+wMgW0TP/WghvzBAWuVFG8q6FGoAyEw=; b=riJ39iKP9MB1qKoukuVMmfk/JT5ejiXf/lElNiBsQzlcjq5BBP5XLVsXw2R+atsiUZ 34vBOeZVzitVLYpjOz1F6oxti1VsNRy56EQoVzo1eYQZMvT4TorcXgLzH5G7GL0XYOCN t358JvkgJZn2vs9BXeLFJAfSXTgYmHEi22aHqNGJJSthPui7cE/2t87WZ1Bbv5dMepE/ N3dU5Orm88tbh5XdtVo5sK4hgt+kj2ahcmzyMuWahfLeT054NwmEFDnGus+qfhPNlfOL 8PIDXht+XxHIinR0xJA8zpwZLMn6x+31bLD+tACXp0JuPmz4qoTEzgV57eqZYK1fbuKX U19w== X-Gm-Message-State: AOAM532EPvHP5syGAUpNcRxKGYEalEE5rL3+ZJiBdu8hNIrDEdps6xrH I78YHUstYYfKWi71i7fqA+KX/ZiKG6ol9aC1OH4= X-Google-Smtp-Source: ABdhPJzVp5g4TmXGKFKys+cMStMUrOj5V3tjfDh8btgvQtHcZhUz4HTK0Qot13w8qV/lgiSFnoaSzA== X-Received: by 2002:ac2:4253:: with SMTP id m19mr696212lfl.81.1598879803345; Mon, 31 Aug 2020 06:16:43 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id b16sm1570435ljk.24.2020.08.31.06.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2020 06:16:42 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Rich Felker , Christoph Hellwig Cc: Mark Brown , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mmc: mmc_spi: Don't use dma mappings unless CONFIG_HAS_DMA is set Date: Mon, 31 Aug 2020 15:16:36 +0200 Message-Id: <20200831131636.51502-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 The commit cd57d07b1e4e ("sh: don't allow non-coherent DMA for NOMMU") made CONFIG_NO_DMA to be set for some platforms, for good reasons. Consequentially, CONFIG_HAS_DMA doesn't get set, which makes the DMA mapping interface to be built as stub functions. For weird reasons this causes the mmc_spi driver to fail to ->probe(), as it relies on the dma mappings APIs, no matter of CONFIG_HAS_DMA is set or not. This is wrong, so let's fix this. Fixes: cd57d07b1e4e ("sh: don't allow non-coherent DMA for NOMMU") Reported-by: Rich Felker Suggested-by: Christoph Hellwig Signed-off-by: Ulf Hansson --- drivers/mmc/host/mmc_spi.c | 86 +++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 34 deletions(-) -- 2.25.1 diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 39bb1e30c2d7..5055a7eb134a 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -1278,6 +1278,52 @@ mmc_spi_detect_irq(int irq, void *mmc) return IRQ_HANDLED; } +#ifdef CONFIG_HAS_DMA +static int mmc_spi_dma_alloc(struct mmc_spi_host *host) +{ + struct spi_device *spi = host->spi; + struct device *dev; + + if (!spi->master->dev.parent->dma_mask) + return 0; + + dev = spi->master->dev.parent; + + host->ones_dma = dma_map_single(dev, host->ones, MMC_SPI_BLOCKSIZE, + DMA_TO_DEVICE); + if (dma_mapping_error(dev, host->ones_dma)) + return -ENOMEM; + + host->data_dma = dma_map_single(dev, host->data, sizeof(*host->data), + DMA_BIDIRECTIONAL); + if (dma_mapping_error(dev, host->data_dma)) { + dma_unmap_single(dev, host->ones_dma, MMC_SPI_BLOCKSIZE, + DMA_TO_DEVICE); + return -ENOMEM; + } + + dma_sync_single_for_cpu(dev, host->data_dma, sizeof(*host->data), + DMA_BIDIRECTIONAL); + + host->dma_dev = dev; + return 0; +} + +static void mmc_spi_dma_free(struct mmc_spi_host *host) +{ + if (!host->dma_dev) + return; + + dma_unmap_single(host->dma_dev, host->ones_dma, MMC_SPI_BLOCKSIZE, + DMA_TO_DEVICE); + dma_unmap_single(host->dma_dev, host->data_dma, sizeof(*host->data), + DMA_BIDIRECTIONAL); +} +#else +static inline mmc_spi_dma_alloc(struct mmc_spi_host *host) { return 0; } +static inline void mmc_spi_dma_free(struct mmc_spi_host *host) {} +#endif + static int mmc_spi_probe(struct spi_device *spi) { void *ones; @@ -1374,23 +1420,9 @@ static int mmc_spi_probe(struct spi_device *spi) if (!host->data) goto fail_nobuf1; - if (spi->master->dev.parent->dma_mask) { - struct device *dev = spi->master->dev.parent; - - host->dma_dev = dev; - host->ones_dma = dma_map_single(dev, ones, - MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE); - if (dma_mapping_error(dev, host->ones_dma)) - goto fail_ones_dma; - host->data_dma = dma_map_single(dev, host->data, - sizeof(*host->data), DMA_BIDIRECTIONAL); - if (dma_mapping_error(dev, host->data_dma)) - goto fail_data_dma; - - dma_sync_single_for_cpu(host->dma_dev, - host->data_dma, sizeof(*host->data), - DMA_BIDIRECTIONAL); - } + status = mmc_spi_dma_alloc(host); + if (status) + goto fail_dma; /* setup message for status/busy readback */ spi_message_init(&host->readback); @@ -1458,20 +1490,12 @@ static int mmc_spi_probe(struct spi_device *spi) fail_add_host: mmc_remove_host(mmc); fail_glue_init: - if (host->dma_dev) - dma_unmap_single(host->dma_dev, host->data_dma, - sizeof(*host->data), DMA_BIDIRECTIONAL); -fail_data_dma: - if (host->dma_dev) - dma_unmap_single(host->dma_dev, host->ones_dma, - MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE); -fail_ones_dma: + mmc_spi_dma_free(host); +fail_dma: kfree(host->data); - fail_nobuf1: mmc_free_host(mmc); mmc_spi_put_pdata(spi); - nomem: kfree(ones); return status; @@ -1489,13 +1513,7 @@ static int mmc_spi_remove(struct spi_device *spi) mmc_remove_host(mmc); - if (host->dma_dev) { - dma_unmap_single(host->dma_dev, host->ones_dma, - MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE); - dma_unmap_single(host->dma_dev, host->data_dma, - sizeof(*host->data), DMA_BIDIRECTIONAL); - } - + mmc_spi_dma_free(host); kfree(host->data); kfree(host->ones);