Skip to content

Commit

Permalink
Merge pull request #21169 from fabian18/pr/mtd_sdmmc_remove_MTD_DRIVE…
Browse files Browse the repository at this point in the history
…R_FLAG_DIRECT_WRITE

{cpu/sam0_common/sam0_sdhc,drivers/mtd}: do not allocate `work_area` twice
  • Loading branch information
fabian18 authored Feb 19, 2025
2 parents 90a9ddb + 9e7a269 commit 8bbeba1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cpu/sam0_common/sam0_sdhc/mtd_sdhc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ static int _init(mtd_dev_t *dev)

#if IS_USED(MODULE_MTD_WRITE_PAGE)
/* TODO: move to MTD layer */
dev->work_area = malloc(SD_MMC_BLOCK_SIZE);
if (dev->work_area == NULL) {
return -ENOMEM;
if (!dev->work_area) {
dev->work_area = malloc(SD_MMC_BLOCK_SIZE);
if (dev->work_area == NULL) {
return -ENOMEM;
}
}
dev->write_size = 1;
#endif
Expand Down
8 changes: 5 additions & 3 deletions drivers/mtd/mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ int mtd_init(mtd_dev_t *mtd)

#ifdef MODULE_MTD_WRITE_PAGE
if ((mtd->driver->flags & MTD_DRIVER_FLAG_DIRECT_WRITE) == 0) {
mtd->work_area = malloc(mtd->pages_per_sector * mtd->page_size);
if (mtd->work_area == NULL) {
res = -ENOMEM;
if (!mtd->work_area) {
mtd->work_area = malloc(mtd->pages_per_sector * mtd->page_size);
if (mtd->work_area == NULL) {
res = -ENOMEM;
}
}
}
#endif
Expand Down

0 comments on commit 8bbeba1

Please sign in to comment.