Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1623396

[PATCH 17/22] mmc: sdhci: Make use of the new sg_map helper function

From Logan Gunthorpe <logang@deltatee.com>
Newsgroups linux.kernel
Subject [PATCH 17/22] mmc: sdhci: Make use of the new sg_map helper function
Date 2017-04-14 00:20 +0200
Message-ID <tvVfQ-Tr-31@gated-at.bofh.it> (permalink)
References <tvV69-P8-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/22] Introduce common scatterlist map function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 18/22] mmc: spi: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 06/22] crypto: hifn_795x: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 04/22] target: Make use of the new sg_map function at 16 call sites Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 16/22] xen-blkfront: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
    RE: [PATCH 16/22] xen-blkfront: Make use of the new sg_map helper  function David Laight <David.Laight@ACULAB.COM> - 2017-04-18 16:20 +0200
      Re: [PATCH 16/22] xen-blkfront: Make use of the new sg_map helper  function Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2017-04-18 16:40 +0200
        Re: [PATCH 16/22] xen-blkfront: Make use of the new sg_map helper  function Logan Gunthorpe <logang@deltatee.com> - 2017-04-18 17:50 +0200
          Re: [PATCH 16/22] xen-blkfront: Make use of the new sg_map helper  function Logan Gunthorpe <logang@deltatee.com> - 2017-04-18 18:00 +0200
          Re: [PATCH 16/22] xen-blkfront: Make use of the new sg_map helper  function Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2017-04-18 18:00 +0200
  [PATCH 10/22] staging: unisys: visorbus: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
    RE: [PATCH 10/22] staging: unisys: visorbus: Make use of the new  sg_map helper function "Kershner, David A" <David.Kershner@unisys.com> - 2017-04-14 18:10 +0200
      Re: [PATCH 10/22] staging: unisys: visorbus: Make use of the new  sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 18:20 +0200
  [PATCH 07/22] crypto: shash, caam: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 12/22] scsi: ipr, pmcraid, isci: Make use of the new sg_map helper in 4 call sites Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 15/22] scsi: libfc, csiostor: Change to sg_copy_buffer in two drivers Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 17/22] mmc: sdhci: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 22/22] memstick: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 19/22] mmc: tmio: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
  [PATCH 02/22] nvmet: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
    Re: [PATCH 02/22] nvmet: Make use of the new sg_map helper function Christoph Hellwig <hch@lst.de> - 2017-04-14 07:10 +0200
      Re: [PATCH 02/22] nvmet: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 07:10 +0200
        Re: [PATCH 02/22] nvmet: Make use of the new sg_map helper function Christoph Hellwig <hch@lst.de> - 2017-04-14 07:20 +0200
  [PATCH 05/22] drm/i915: Make use of the new sg_map helper function Logan Gunthorpe <logang@deltatee.com> - 2017-04-14 00:20 +0200
    Re: [PATCH 05/22] drm/i915: Make use of the new sg_map helper  function Daniel Vetter <daniel@ffwll.ch> - 2017-04-18 08:50 +0200
      Re: [PATCH 05/22] drm/i915: Make use of the new sg_map helper  function Logan Gunthorpe <logang@deltatee.com> - 2017-04-18 17:50 +0200

csiph-web