From: Juergen Borleis <jbe@pengutronix.de>
To: linux-mmc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, festevam@gmail.com,
wsa+renesas@sang-engineering.com, dianders@chromium.org,
ulf.hansson@linaro.org, kernel@pengutronix.de
Subject: [PATCH 2/2] mmc: mxcmmc: don't expect a DMA operation if DMA seems present
Date: Thu, 29 Jul 2021 09:29:29 +0200 [thread overview]
Message-ID: <20210729072929.10267-3-jbe@pengutronix.de> (raw)
In-Reply-To: <20210729072929.10267-1-jbe@pengutronix.de>
Change the driver's default behaviour from DMA to PIO for each request.
Preparing DMA can fail or be prevented by other causes. Switch to a DMA
operation only, if it is really possible.
This avoids a NULL pointer dereference on shutdown in mxcmci_start_cmd()
where it tries to store a DMA callback configuration into mxcmci_host::desc
which isn't setup a this point of time.
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
---
drivers/mmc/host/mxcmmc.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index 611f827..41feea9 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -293,14 +293,13 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
mxcmci_writew(host, blksz, MMC_REG_BLK_LEN);
host->datasize = datasize;
- if (!mxcmci_use_dma(host))
- return 0;
+ if (host->dma == NULL)
+ return 0; /* Keep PIO */
+ /* Avoid the use of DMA on short transfers, e.g. non-sectors for example */
for_each_sg(data->sg, sg, data->sg_len, i) {
- if (sg->offset & 3 || sg->length & 3 || sg->length < 512) {
- host->do_dma = 0;
- return 0;
- }
+ if (sg->offset & 3 || sg->length & 3 || sg->length < 512)
+ return 0; /* Keep PIO */
}
if (data->flags & MMC_DATA_READ) {
@@ -325,9 +324,11 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
if (!host->desc) {
dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len,
host->dma_dir);
- host->do_dma = 0;
- return 0; /* Fall back to PIO */
+ return 0; /* Keep PIO */
}
+
+ /* DMA is possible */
+ host->do_dma = 1;
wmb();
dmaengine_submit(host->desc);
@@ -747,8 +748,11 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req)
host->req = req;
host->cmdat &= ~CMD_DAT_CONT_INIT;
- if (host->dma)
- host->do_dma = 1;
+ /*
+ * Default always to PIO. DMA will be enabled in
+ * mxcmci_setup_data() if possible
+ */
+ host->do_dma = 0;
if (req->data) {
error = mxcmci_setup_data(host, req->data);
--
2.20.1
prev parent reply other threads:[~2021-07-29 7:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-29 7:29 Make the i.MX MMC device using DMA again Juergen Borleis
2021-07-29 7:29 ` [PATCH 1/2] mmc: mxcmmc: really configure the DMA on demand Juergen Borleis
2021-08-11 11:36 ` Ulf Hansson
2021-07-29 7:29 ` Juergen Borleis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210729072929.10267-3-jbe@pengutronix.de \
--to=jbe@pengutronix.de \
--cc=dianders@chromium.org \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).