mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Hilliard <thirtythreeforty@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-mips@linux-mips.org, linux-kernel@vger.kernel.org,
	George Hilliard <thirtythreeforty@gmail.com>
Subject: [PATCH v3 3/3] staging: mt7621-mmc: Check for nonzero number of scatterlist entries
Date: Wed, 20 Mar 2019 16:42:05 -0600	[thread overview]
Message-ID: <20190320224204.10243-4-thirtythreeforty@gmail.com> (raw)
In-Reply-To: <20190320224204.10243-1-thirtythreeforty@gmail.com>

The buffer descriptor setup loop is correct only if it is setting up at
least one bd struct.  Besides, there is an error if dma_map_sg() returns
0, which is possible and must be handled.

Additionally, remove the BUG_ON() checking sglen, which is unnecessary
because we configure DMA with that constraint during init.

Signed-off-by: George Hilliard <thirtythreeforty@gmail.com>
---
v2: Rebased v1
v3: Remove existing and added BUG_ON() in v2, and handle dma_map_sg
    failure gracefully.

 drivers/staging/mt7621-mmc/sd.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 139533606863..cf2ad06112eb 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -593,8 +593,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
 	struct bd *bd;
 	u32 j;
 
-	BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
-
 	gpd = dma->gpd;
 	bd  = dma->bd;
 
@@ -687,6 +685,13 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
 		data->sg_count = dma_map_sg(mmc_dev(mmc), data->sg,
 					    data->sg_len,
 					    mmc_get_dma_dir(data));
+
+		if (data->sg_count == 0) {
+			dev_err(mmc_dev(host->mmc), "failed to map DMA for transfer\n");
+			data->error = -ENOMEM;
+			goto done;
+		}
+
 		msdc_dma_setup(host, &host->dma, data->sg,
 			       data->sg_count);
 
-- 
2.21.0


  parent reply	other threads:[~2019-03-20 22:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 22:42 [PATCH v3 0/3] mt7621-mmc driver correctness fixes George Hilliard
2019-03-20 22:42 ` [PATCH v3 1/3] staging: mt7621-mmc: Fix warning when reloading module with debug msgs enabled George Hilliard
2019-03-20 22:42 ` [PATCH v3 2/3] staging: mt7621-mmc: Initialize completions a single time during probe George Hilliard
2019-03-22 14:19   ` Greg Kroah-Hartman
2019-03-20 22:42 ` George Hilliard [this message]
2019-03-22 14:20 ` [PATCH v3 0/3] mt7621-mmc driver correctness fixes Greg Kroah-Hartman

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=20190320224204.10243-4-thirtythreeforty@gmail.com \
    --to=thirtythreeforty@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    /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

all inboxes | Powered by JetHome®