Skip to contentSkip to conversation

mtdswap: Fine-tuning for three function implementations

PATCH New SF Markus Elfring 1 participant 4 messages May 8, 2017

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

cover mtdswap: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 8 May 2017 17:02:03 +0200

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Reduce function calls for sequence output in mtdswap_show() Improve two size determinations in mtdswap_add_mtd() Improve a size determination in mtdswap_erase_block()

 drivers/mtd/mtdswap.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/3 mtdswap: Reduce function calls for sequence output in mtdswap_show()

From: Markus Elfring <[email protected]>
Date: Mon, 8 May 2017 16:02:34 +0200

Two line breaks were put into a sequence by separate function calls. Print the same data together with adjusted seq_printf() calls instead.

This issue was detected by using the Coccinelle software.

---
 drivers/mtd/mtdswap.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/mtd/mtdswap.c +2 -7
index f12879a3d4ff..0805f45c5139 100644
@@ -1283,19 +1283,14 @@ static int mtdswap_show(struct seq_file *s, void *data)
 			"erased %u times\n",
 			cwp, d->pages_per_eblk - cwp, cwecount);
 
-	seq_printf(s, "total erasures: %lu\n", sum);
-
-	seq_puts(s, "\n");
-
+	seq_printf(s, "total erasures: %lu\n\n", sum);
 	seq_printf(s, "mtdswap_readsect count: %llu\n", d->sect_read_count);
 	seq_printf(s, "mtdswap_writesect count: %llu\n", d->sect_write_count);
 	seq_printf(s, "mtdswap_discard count: %llu\n", d->discard_count);
 	seq_printf(s, "mtd read count: %llu\n", d->mtd_read_count);
 	seq_printf(s, "mtd write count: %llu\n", d->mtd_write_count);
 	seq_printf(s, "discarded pages count: %llu\n", d->discard_page_count);
-
-	seq_puts(s, "\n");
-	seq_printf(s, "total pages: %u\n", pages);
+	seq_printf(s, "\ntotal pages: %u\n", pages);
 	seq_printf(s, "pages mapped: %u\n", mapped);
 
 	return 0;
Signature · 1 line
2.12.2
#2 lore raw

PATCH 2/3 mtdswap: Improve two size determinations in mtdswap_add_mtd()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 8 May 2017 16:18:49 +0200

Replace the specification of two data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/mtd/mtdswap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/mtdswap.c +2 -2
index 0805f45c5139..f73fb0909b0c 100644
@@ -1485,11 +1485,11 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 		"%u spare, %u bad blocks\n",
 		MTDSWAP_PREFIX, part, swap_size / 1024, spare_cnt, bad_blocks);
 
-	d = kzalloc(sizeof(struct mtdswap_dev), GFP_KERNEL);
+	d = kzalloc(sizeof(*d), GFP_KERNEL);
 	if (!d)
 		return;
 
-	mbd_dev = kzalloc(sizeof(struct mtd_blktrans_dev), GFP_KERNEL);
+	mbd_dev = kzalloc(sizeof(*mbd_dev), GFP_KERNEL);
 	if (!mbd_dev) {
 		kfree(d);
 		return;
Signature · 1 line
2.12.2
#3 lore raw

PATCH 3/3 mtdswap: Improve a size determination in mtdswap_erase_block()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 8 May 2017 16:51:30 +0200

Replace the specification of a data structure by a name for a local variable as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.

---
 drivers/mtd/mtdswap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/mtdswap.c +1 -2
index f73fb0909b0c..c748515f8533 100644
@@ -559,8 +559,7 @@ static int mtdswap_erase_block(struct mtdswap_dev *d, struct swap_eb *eb)
 
 retry:
 	init_waitqueue_head(&wq);
-	memset(&erase, 0, sizeof(struct erase_info));
-
+	memset(&erase, 0, sizeof(erase));
 	erase.mtd	= mtd;
 	erase.callback	= mtdswap_erase_callback;
 	erase.addr	= mtdswap_eb_offset(d, eb);
Signature · 1 line
2.12.2