From 2f7cf351737e985691ab81b290908ae0dca2d07e Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 21 Mar 2022 11:52:17 +0100 Subject: [PATCH] drivers/mtd_mci: fix sub-page writes When doing sub-page writes, we would return a value that is larger than the amount of bytes written, causing an underflow in the MTD layer. --- drivers/mtd_mci/mtd_mci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd_mci/mtd_mci.c b/drivers/mtd_mci/mtd_mci.c index f1094f0e6a..7c83260417 100644 --- a/drivers/mtd_mci/mtd_mci.c +++ b/drivers/mtd_mci/mtd_mci.c @@ -111,7 +111,7 @@ static int mtd_mci_write_page(mtd_dev_t *dev, const void *buff, uint32_t page, return -EIO; } - return pages * SD_HC_BLOCK_SIZE; + return min(size, pages * SD_HC_BLOCK_SIZE); } static int mtd_mci_erase_sector(mtd_dev_t *dev, uint32_t sector, uint32_t count)