]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
fix(st-sdmmc): check transfer size before filling register
authorYann Gautier <yann.gautier@st.com>
Mon, 21 Nov 2022 12:36:53 +0000 (13:36 +0100)
committerYann Gautier <yann.gautier@st.com>
Wed, 7 Dec 2022 17:25:13 +0000 (18:25 +0100)
Fix MISRA C2012-10.3:
The value of an expression shall not be assigned to an object with
a narrower essential type or of a different essential type category.

Check buffer size is less than 4GB before casting the command argument.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: Iac1afcfe905c99b22cb39dc4104d351b0e647e5d

drivers/st/mmc/stm32_sdmmc2.c

index 6bdd782aeab3fa9c3b9f166e21d041fc4001bcac..1ee3580853dc3fc2025fbbaea534f168b60b7fc6 100644 (file)
@@ -528,12 +528,12 @@ static int stm32_sdmmc2_prepare(int lba, uintptr_t buf, size_t size)
        uint32_t data_ctrl = SDMMC_DCTRLR_DTDIR;
        uint32_t arg_size;
 
-       assert(size != 0U);
+       assert((size != 0U) && (size <= UINT32_MAX));
 
        if (size > MMC_BLOCK_SIZE) {
                arg_size = MMC_BLOCK_SIZE;
        } else {
-               arg_size = size;
+               arg_size = (uint32_t)size;
        }
 
        sdmmc2_params.use_dma = plat_sdmmc2_use_dma(base, buf);