From: Lukasz Majewski Date: Mon, 3 Dec 2018 09:20:47 +0000 (+0100) Subject: nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc X-Git-Url: http://git.dujemihanovic.xyz/img/sics.gif?a=commitdiff_plain;h=254409dbe836633b079968c0e7686ecd09b45dc7;p=u-boot.git nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc 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 Reviewed-by: Stefan Agner --- diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c index 619d0403e9..9baf5fa37a 100644 --- a/drivers/mtd/nand/raw/vf610_nfc.c +++ b/drivers/mtd/nand/raw/vf610_nfc.c @@ -641,7 +641,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;