mmc: Fix dma_map_sg error check
Subsystems (4)
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
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.
--- 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
@@ -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
Re: [PATCH 1/2] mmc: meson-mx-sdhc: Fix error check for dma_map_sg
Quoted 14 lines · Jack Wang
dma_map_sgreturn 0 on error, also change the type fordma_lenfrom 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
Signed-off-by Jack Wang <[email protected]>
Thank you for this patch! It's:
Best regards,
Martin
PATCH 2/2 mmc: jz4740_mmc: Fix error check for dma_map_sg
In reply to Jack Wangdma_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
@@ -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
Re: [PATCH 2/2] mmc: jz4740_mmc: Fix error check for dma_map_sg
Hi Jack,
Quoted 9 lines · Jack Wang
dma_map_sgreturn 0 on error.Cc Paul Cercueil <[email protected]>Cc Ulf Hansson <[email protected]>Signed-off-by Jack Wang <[email protected]>
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@@ -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
-1return 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
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_sgreturn 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 fordma_map_sg
mmc:jz4740_mmc: Fix error check fordma_map_sgdrivers/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