* [PATCH master] mci: core: allocate memory used for DMA with dma_alloc
@ 2024-04-23 6:04 Ahmad Fatoum
2024-04-23 6:26 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-04-23 6:04 UTC (permalink / raw)
To: barebox; +Cc: Enrico Scholz, Ahmad Fatoum
Memory allocated by normal malloc may not fulfill the alignment
requirements for DMA.
This fixes memory corruption observed on the i.MX8MP when the
DMA-enabled eSDHC driver attempts to probe an eMMC.
This issues always existed, but only after commit 65ef5d885263
("ARM64: let 'end' point after the range in cache functions"), the whole
512 bytes were getting invalidated, which corrupted the TLSF malloc
header of the block after it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/mmc.c | 9 +++++----
drivers/mci/mci-core.c | 12 ++++++------
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/commands/mmc.c b/commands/mmc.c
index fa01b89cdf42..041a721d3661 100644
--- a/commands/mmc.c
+++ b/commands/mmc.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <string.h>
#include <getopt.h>
+#include <dma.h>
static int mmc_enh_area_setmax(struct mci *mci, u8 *ext_csd)
{
@@ -115,7 +116,7 @@ static int do_mmc_enh_area(int argc, char *argv[])
if (ret)
goto error;
- free(ext_csd);
+ dma_free(ext_csd);
if (set_completed) {
ret = mmc_partitioning_complete(mci);
@@ -127,7 +128,7 @@ static int do_mmc_enh_area(int argc, char *argv[])
return COMMAND_SUCCESS;
error:
- free(ext_csd);
+ dma_free(ext_csd);
return COMMAND_ERROR;
}
@@ -183,12 +184,12 @@ static int do_mmc_write_reliability(int argc, char *argv[])
}
}
- free(ext_csd);
+ dma_free(ext_csd);
return COMMAND_SUCCESS;
error:
- free(ext_csd);
+ dma_free(ext_csd);
return COMMAND_ERROR;
}
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 6d4abe321bfa..1d383e6449e9 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -545,12 +545,12 @@ u8 *mci_get_ext_csd(struct mci *mci)
u8 *ext_csd;
int ret;
- ext_csd = xmalloc(512);
+ ext_csd = dma_alloc(512);
ret = mci_send_ext_csd(mci, ext_csd);
if (ret) {
printf("Failure to read EXT_CSD register\n");
- free(ext_csd);
+ dma_free(ext_csd);
return ERR_PTR(-EIO);
}
@@ -666,7 +666,7 @@ static int mmc_change_freq(struct mci *mci)
char cardtype;
int err;
- mci->ext_csd = xmalloc(512);
+ mci->ext_csd = dma_alloc(512);
mci->card_caps = 0;
/* Only version 4 supports high-speed */
@@ -1124,7 +1124,7 @@ static int mmc_compare_ext_csds(struct mci *mci, enum mci_bus_width bus_width)
if (bus_width == MMC_BUS_WIDTH_1)
return 0;
- bw_ext_csd = xmalloc(512);
+ bw_ext_csd = dma_alloc(512);
err = mci_send_ext_csd(mci, bw_ext_csd);
if (err) {
dev_info(&mci->dev, "mci_send_ext_csd failed with %d\n", err);
@@ -1173,7 +1173,7 @@ static int mmc_compare_ext_csds(struct mci *mci, enum mci_bus_width bus_width)
0 : -EINVAL;
out:
- free(bw_ext_csd);
+ dma_free(bw_ext_csd);
return err;
}
@@ -2220,7 +2220,7 @@ static int mci_get_partition_setting_completed(struct mci *mci)
ret = ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED];
- free(ext_csd);
+ dma_free(ext_csd);
return ret;
}
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH master] mci: core: allocate memory used for DMA with dma_alloc
2024-04-23 6:04 [PATCH master] mci: core: allocate memory used for DMA with dma_alloc Ahmad Fatoum
@ 2024-04-23 6:26 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-04-23 6:26 UTC (permalink / raw)
To: barebox, Ahmad Fatoum; +Cc: Enrico Scholz
On Tue, 23 Apr 2024 08:04:35 +0200, Ahmad Fatoum wrote:
> Memory allocated by normal malloc may not fulfill the alignment
> requirements for DMA.
>
> This fixes memory corruption observed on the i.MX8MP when the
> DMA-enabled eSDHC driver attempts to probe an eMMC.
>
> This issues always existed, but only after commit 65ef5d885263
> ("ARM64: let 'end' point after the range in cache functions"), the whole
> 512 bytes were getting invalidated, which corrupted the TLSF malloc
> header of the block after it.
>
> [...]
Applied, thanks!
[1/1] mci: core: allocate memory used for DMA with dma_alloc
https://git.pengutronix.de/cgit/barebox/commit/?id=b986aad24ab8 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-23 6:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 6:04 [PATCH master] mci: core: allocate memory used for DMA with dma_alloc Ahmad Fatoum
2024-04-23 6:26 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox