Skip to contentSkip to conversation

nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc

PATCH New Lukasz Majewski 2 participants 2 messages Dec 3, 2018 – Dec 6, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---

 drivers/mtd/nand/raw/vf610_nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/vf610_nfc.c +1 -1
index fce7e5f299..3326c2b096 100644
@@ -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;
Signature · 1 line
2.11.0
maintainer
#1 lore raw

PATCH 1/1 nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc

Quoted 7 lines · Lukasz Majewski

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.

Quoted 6 lines

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.

Looks good:

--
Stefan

Quoted 20 lines

---

 drivers/mtd/nand/raw/vf610_nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/vf610_nfc.c +1 -1
index fce7e5f299..3326c2b096 100644
@@ -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;