lkml.org 
[lkml]   [2017]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH 17/22] mmc: sdhci: Make use of the new sg_map helper function
Straightforward conversion, except due to the lack of error path we
have to WARN if the memory in the SGL is not mappable.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
drivers/mmc/host/sdhci.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 63bc33a..af0c107 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -497,15 +497,34 @@ static int sdhci_pre_dma_transfer(struct sdhci_host *host,
return sg_count;
}

+/*
+ * Note this function may return PTR_ERR and must be checked.
+ */
static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
{
+ void *ret;
+
local_irq_save(*flags);
- return kmap_atomic(sg_page(sg)) + sg->offset;
+
+ ret = sg_map(sg, SG_KMAP_ATOMIC);
+ if (IS_ERR(ret)) {
+ /*
+ * This should really never happen unless the code is changed
+ * to use memory that is not mappable in the sg. Seeing there
+ * doesn't seem to be any error path out of here, we can only
+ * WARN.
+ */
+ WARN(1, "Non-mappable memory used in sg!");
+ local_irq_restore(*flags);
+ }
+
+ return ret;
}

-static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
+static void sdhci_kunmap_atomic(struct scatterlist *sg, void *buffer,
+ unsigned long *flags)
{
- kunmap_atomic(buffer);
+ sg_unmap(sg, buffer, SG_KMAP_ATOMIC);
local_irq_restore(*flags);
}

@@ -568,8 +587,11 @@ static void sdhci_adma_table_pre(struct sdhci_host *host,
if (offset) {
if (data->flags & MMC_DATA_WRITE) {
buffer = sdhci_kmap_atomic(sg, &flags);
+ if (IS_ERR(buffer))
+ return;
+
memcpy(align, buffer, offset);
- sdhci_kunmap_atomic(buffer, &flags);
+ sdhci_kunmap_atomic(sg, buffer, &flags);
}

/* tran, valid */
@@ -646,8 +668,11 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
(sg_dma_address(sg) & SDHCI_ADMA2_MASK);

buffer = sdhci_kmap_atomic(sg, &flags);
+ if (IS_ERR(buffer))
+ return;
+
memcpy(buffer, align, size);
- sdhci_kunmap_atomic(buffer, &flags);
+ sdhci_kunmap_atomic(sg, buffer, &flags);

align += SDHCI_ADMA2_ALIGN;
}
--
2.1.4
\
 
 \ /
  Last update: 2017-04-14 00:11    [W:0.510 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site