diff mbox series

[U-Boot] nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc

Message ID 20181203092047.2280-1-lukma@denx.de
State Accepted
Commit 254409dbe836633b079968c0e7686ecd09b45dc7
Delegated to: Stefano Babic
Headers show
Series [U-Boot] nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc | expand

Commit Message

Lukasz Majewski Dec. 3, 2018, 9:20 a.m. UTC
Without this change it is possible that Vybrid's NFC driver malloc() call
will obtain some memory used (and correctly free'd) by some previous
driver (in this case pinctrl for Vybrid).

As a result some fields of struct nfc - in out case mtd->_get_device - are
"pre initialized" with some random values.

On the latter stage of booting, when e.g. somebody calls 'mtdparts default'
the "data abort" is observed when __get_mtd_device() function is called.

The mtd->_get_device pointer is not NULL and wrong value is referenced.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---

 drivers/mtd/nand/raw/vf610_nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefan Agner Dec. 6, 2018, 12:13 p.m. UTC | #1
On 03.12.2018 10:20, Lukasz Majewski wrote:
> Without this change it is possible that Vybrid's NFC driver malloc() call
> will obtain some memory used (and correctly free'd) by some previous
> driver (in this case pinctrl for Vybrid).
> 
> As a result some fields of struct nfc - in out case mtd->_get_device - are
> "pre initialized" with some random values.
> 
> On the latter stage of booting, when e.g. somebody calls 'mtdparts default'
> the "data abort" is observed when __get_mtd_device() function is called.
> 
> The mtd->_get_device pointer is not NULL and wrong value is referenced.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>

Looks good:

Reviewed-by: Stefan Agner <stefan.agner@toradex.com>

--
Stefan

> 
> ---
> 
>  drivers/mtd/nand/raw/vf610_nfc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
> index fce7e5f299..3326c2b096 100644
> --- a/drivers/mtd/nand/raw/vf610_nfc.c
> +++ b/drivers/mtd/nand/raw/vf610_nfc.c
> @@ -646,7 +646,7 @@ static int vf610_nfc_nand_init(int devnum, void
> __iomem *addr)
>  		.flash_bbt = 1,
>  	};
>  
> -	nfc = malloc(sizeof(*nfc));
> +	nfc = calloc(1, sizeof(*nfc));
>  	if (!nfc) {
>  		printf(KERN_ERR "%s: Memory exhausted!\n", __func__);
>  		return -ENOMEM;
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index fce7e5f299..3326c2b096 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -646,7 +646,7 @@  static int vf610_nfc_nand_init(int devnum, void __iomem *addr)
 		.flash_bbt = 1,
 	};
 
-	nfc = malloc(sizeof(*nfc));
+	nfc = calloc(1, sizeof(*nfc));
 	if (!nfc) {
 		printf(KERN_ERR "%s: Memory exhausted!\n", __func__);
 		return -ENOMEM;