Skip to contentSkip to conversation

mtd: docprobe: use kzalloc instead

PATCH In review Artem Bityutskiy 2 participants 4 messages Dec 29, 2011

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

PATCH 1/2 mtd: docprobe: use kzalloc instead

From: Artem Bityutskiy <[email protected]>

Instead of calling 'kmalloc()' and them 'memeset(0)', use 'kzalloc()'.

---
 drivers/mtd/devices/docprobe.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
drivers/mtd/devices/docprobe.c +1 -6
index 45116bb..31b84aa 100644
@@ -241,8 +241,7 @@ static void __init DoC_Probe(unsigned long physadr)
 			return;
 		}
 		docfound = 1;
-		mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
-
+		mtd = kzmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
 		if (!mtd) {
 			printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
 			iounmap(docptr);
@@ -250,10 +249,6 @@ static void __init DoC_Probe(unsigned long physadr)
 		}
 
 		this = (struct DiskOnChip *)(&mtd[1]);
-
-		memset((char *)mtd,0, sizeof(struct mtd_info));
-		memset((char *)this, 0, sizeof(struct DiskOnChip));
-
 		mtd->priv = this;
 		this->virtadr = docptr;
 		this->physadr = physadr;
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 2/2 mtd: doc: do not initialize mtd_info fields to 0 or NULL

From: Artem Bityutskiy <[email protected]>

The 'struct mtd_info' object is allocated with 'kzalloc()', so it contains only zeroes - no need to initialize various fields to 0 or NULL.

---
 drivers/mtd/devices/doc2000.c     |    9 ---------
 drivers/mtd/devices/doc2001.c     |    8 --------
 drivers/mtd/devices/doc2001plus.c |    9 ---------
 drivers/mtd/devices/docg3.c       |    3 ---
 4 files changed, 0 insertions(+), 29 deletions(-)
drivers/mtd/devices/doc2000.c +0 -9
index e9fad91..b1cdf64 100644
@@ -562,23 +562,14 @@ void DoC2k_init(struct mtd_info *mtd)
 
 	mtd->type = MTD_NANDFLASH;
 	mtd->flags = MTD_CAP_NANDFLASH;
-	mtd->size = 0;
-	mtd->erasesize = 0;
 	mtd->writesize = 512;
 	mtd->oobsize = 16;
 	mtd->owner = THIS_MODULE;
 	mtd->erase = doc_erase;
-	mtd->point = NULL;
-	mtd->unpoint = NULL;
 	mtd->read = doc_read;
 	mtd->write = doc_write;
 	mtd->read_oob = doc_read_oob;
 	mtd->write_oob = doc_write_oob;
-	mtd->sync = NULL;
-
-	this->totlen = 0;
-	this->numchips = 0;
-
 	this->curfloor = -1;
 	this->curchip = -1;
 	mutex_init(&this->lock);
drivers/mtd/devices/doc2001.c +0 -8
index a3f7a27..7543b98 100644
@@ -343,25 +343,17 @@ void DoCMil_init(struct mtd_info *mtd)
 
 	mtd->type = MTD_NANDFLASH;
 	mtd->flags = MTD_CAP_NANDFLASH;
-	mtd->size = 0;
 
 	/* FIXME: erase size is not always 8KiB */
 	mtd->erasesize = 0x2000;
-
 	mtd->writesize = 512;
 	mtd->oobsize = 16;
 	mtd->owner = THIS_MODULE;
 	mtd->erase = doc_erase;
-	mtd->point = NULL;
-	mtd->unpoint = NULL;
 	mtd->read = doc_read;
 	mtd->write = doc_write;
 	mtd->read_oob = doc_read_oob;
 	mtd->write_oob = doc_write_oob;
-	mtd->sync = NULL;
-
-	this->totlen = 0;
-	this->numchips = 0;
 	this->curfloor = -1;
 	this->curchip = -1;
 
drivers/mtd/devices/doc2001plus.c +0 -9
index 99351bc..177510d 100644
@@ -467,23 +467,14 @@ void DoCMilPlus_init(struct mtd_info *mtd)
 
 	mtd->type = MTD_NANDFLASH;
 	mtd->flags = MTD_CAP_NANDFLASH;
-	mtd->size = 0;
-
-	mtd->erasesize = 0;
 	mtd->writesize = 512;
 	mtd->oobsize = 16;
 	mtd->owner = THIS_MODULE;
 	mtd->erase = doc_erase;
-	mtd->point = NULL;
-	mtd->unpoint = NULL;
 	mtd->read = doc_read;
 	mtd->write = doc_write;
 	mtd->read_oob = doc_read_oob;
 	mtd->write_oob = doc_write_oob;
-	mtd->sync = NULL;
-
-	this->totlen = 0;
-	this->numchips = 0;
 	this->curfloor = -1;
 	this->curchip = -1;
 
drivers/mtd/devices/docg3.c +0 -3
index 22d5099..ad11ef0a 100644
@@ -1821,13 +1821,10 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)
 	mtd->oobsize = DOC_LAYOUT_OOB_SIZE;
 	mtd->owner = THIS_MODULE;
 	mtd->erase = doc_erase;
-	mtd->point = NULL;
-	mtd->unpoint = NULL;
 	mtd->read = doc_read;
 	mtd->write = doc_write;
 	mtd->read_oob = doc_read_oob;
 	mtd->write_oob = doc_write_oob;
-	mtd->sync = NULL;
 	mtd->block_isbad = doc_block_isbad;
 	mtd->ecclayout = &docg3_oobinfo;
 }
Signature · 1 line
1.7.7.3
#2 lore raw
In reply to Artem Bityutskiy

drivers/mtd/devices/docprobe.c static void __init DoC_Probe(unsigned long physadr) · line 244

Quoted 1 line · Artem Bityutskiy
drivers/mtd/devices/docprobe.c +1 -0
+		mtd = kzmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);

I guess you mean kzalloc() and not kzmalloc().

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#3 lore raw
Quoted 6 lines · Thomas Petazzoni

drivers/mtd/devices/docprobe.c static void __init DoC_Probe(unsigned long physadr) · line 244

Quoted 1 line · Artem Bityutskiy
drivers/mtd/devices/docprobe.c +1 -0
+		mtd = kzmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);

I guess you mean kzalloc() and not kzmalloc().

Yes, I have actually had fixed that but then sent the bogus patcy version, thanks!

Artem.