Skip to contentSkip to conversation

mmc: Fix dma_map_sg error check

PATCH In review Jack Wang 4 participants 6 messages Aug 25, 2022 – Aug 27, 2022

Subsystems (4)
lore
Share & tools
lore

Jack Wang

author
#0 lore raw

cover mmc: Fix dma_map_sg error check

Hi, all,

While working on a bugfix on RTRS[1], I noticed there are quite a few other drivers have the same problem, due to the fact dma_map_sg return 0 on error, not like most of the cases, return negative value for error.

I "grep -A 5 dma_map_sg' in kernel tree, and audit/fix the one I feel is buggy, hence this patchset. As suggested by Christoph Hellwig, I now send the patches per subsystem, this is for mmc subsystem.

Thanks!

[1] https://lore.kernel.org/linux-rdma/[email protected]/T/#t

Jack Wang (2):
mmc: meson-mx-sdhc: Fix error check for dma_map_sg
mmc: jz4740_mmc: Fix error check for dma_map_sg

 drivers/mmc/host/jz4740_mmc.c        | 4 ++--
 drivers/mmc/host/meson-mx-sdhc-mmc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 mmc: meson-mx-sdhc: Fix error check for dma_map_sg

dma_map_sg return 0 on error, also change the type for dma_len from int to unsigned int.

Cc Ulf Hansson <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Jerome Brunet <[email protected]>
Cc Martin Blumenstingl <[email protected]>
---
 drivers/mmc/host/meson-mx-sdhc-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/meson-mx-sdhc-mmc.c +2 -2
index e92e63cb5641..da85c2f2acb8 100644
@@ -381,14 +381,14 @@ static void meson_mx_sdhc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 static int meson_mx_sdhc_map_dma(struct mmc_host *mmc, struct mmc_request *mrq)
 {
 	struct mmc_data *data = mrq->data;
-	int dma_len;
+	unsigned int dma_len;
 
 	if (!data)
 		return 0;
 
 	dma_len = dma_map_sg(mmc_dev(mmc), data->sg, data->sg_len,
 			     mmc_get_dma_dir(data));
-	if (dma_len <= 0) {
+	if (!dma_len) {
 		dev_err(mmc_dev(mmc), "dma_map_sg failed\n");
 		return -ENOMEM;
 	}
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mmc: meson-mx-sdhc: Fix error check for dma_map_sg

Quoted 14 lines · Jack Wang

dma_map_sg return 0 on error, also change the type for dma_len from int to unsigned int.

Cc Ulf Hansson <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Jerome Brunet <[email protected]>
Cc Martin Blumenstingl <[email protected]>
Quoted 1 line

Thank you for this patch! It's:

Best regards,
Martin

author
#3 lore raw

PATCH 2/2 mmc: jz4740_mmc: Fix error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error.

---
 drivers/mmc/host/jz4740_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/jz4740_mmc.c +2 -2
index b1d563b2ed1b..dc2db9c185ea 100644
@@ -298,7 +298,7 @@ static int jz4740_mmc_prepare_dma_data(struct jz4740_mmc_host *host,
 {
 	struct dma_chan *chan = jz4740_mmc_get_dma_chan(host, data);
 	enum dma_data_direction dir = mmc_get_dma_dir(data);
-	int sg_count;
+	unsigned int sg_count;
 
 	if (data->host_cookie == COOKIE_PREMAPPED)
 		return data->sg_count;
@@ -308,7 +308,7 @@ static int jz4740_mmc_prepare_dma_data(struct jz4740_mmc_host *host,
 			data->sg_len,
 			dir);
 
-	if (sg_count <= 0) {
+	if (!sg_count) {
 		dev_err(mmc_dev(host->mmc),
 			"Failed to map scatterlist for DMA operation\n");
 		return -EINVAL;
Signature · 1 line
2.34.1
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] mmc: jz4740_mmc: Fix error check for dma_map_sg

Hi Jack,

Quoted 9 lines · Jack Wang

dma_map_sg return 0 on error.

Cheers,
-Paul

Quoted 31 lines
---
 drivers/mmc/host/jz4740_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/jz4740_mmc.c +1 -1
index b1d563b2ed1b..dc2db9c185ea 100644
@@ -298,7 +298,7 @@ static int jz4740_mmc_prepare_dma_data(struct 
 jz4740_mmc_host *host,
 {
 	struct dma_chan *chan = jz4740_mmc_get_dma_chan(host, data);
 	enum dma_data_direction dir = mmc_get_dma_dir(data);
-	int sg_count;
+	unsigned int sg_count;
 
 	if (data->host_cookie == COOKIE_PREMAPPED)
drivers/mmc/host/jz4740_mmc.c +1 -1
 		return data->sg_count;
@@ -308,7 +308,7 @@ static int jz4740_mmc_prepare_dma_data(struct 
 jz4740_mmc_host *host,
 			data->sg_len,
 			dir);
 
-	if (sg_count <= 0) {
+	if (!sg_count) {
 		dev_err(mmc_dev(host->mmc),
 			"Failed to map scatterlist for DMA operation\n");

return -EINVAL;
--
2.34.1

#5 lore raw
In reply to Jack Wang
Quoted 15 lines · Jack Wang

Hi, all,

While working on a bugfix on RTRS[1], I noticed there are quite a few other drivers have the same problem, due to the fact dma_map_sg return 0 on error, not like most of the cases, return negative value for error.

I "grep -A 5 dma_map_sg' in kernel tree, and audit/fix the one I feel is buggy, hence this patchset. As suggested by Christoph Hellwig, I now send the patches per subsystem, this is for mmc subsystem.

Thanks!

[1] https://lore.kernel.org/linux-rdma/[email protected]/T/#t

Quoted 8 lines

Jack Wang (2):
mmc: meson-mx-sdhc: Fix error check for dma_map_sg
mmc: jz4740_mmc: Fix error check for dma_map_sg

 drivers/mmc/host/jz4740_mmc.c        | 4 ++--
 drivers/mmc/host/meson-mx-sdhc-mmc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

The series, applied for next, thanks!

Kind regards
Uffe