mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations
@ 2018-01-06 15:06 SF Markus Elfring
  2018-01-06 15:07 ` [PATCH 1/5] mtd/rfd_ftl: Delete an error message for a failed memory allocation in scan_header() SF Markus Elfring
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-01-06 15:06 UTC (permalink / raw)
  To: linux-mtd, Boris Brezillon, Brian Norris, Cyrille Pitchen,
	David Woodhouse, Marek Vasut, Richard Weinberger
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jan 2018 16:00:01 +0100

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

Markus Elfring (5):
  Delete an error message for a failed memory allocation in scan_header()
  Less function calls in scan_header() after error detection
  Improve a size determination in two functions
  Return directly after a failed kmalloc() in erase_block()
  Add some spaces for better code readability

 drivers/mtd/rfd_ftl.c | 45 +++++++++++++++++++--------------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

-- 
2.15.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] mtd/rfd_ftl: Delete an error message for a failed memory allocation in scan_header()
  2018-01-06 15:06 [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations SF Markus Elfring
@ 2018-01-06 15:07 ` SF Markus Elfring
  2018-01-06 15:08 ` [PATCH 2/5] mtd/rfd_ftl: Less function calls in scan_header() after error detection SF Markus Elfring
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-01-06 15:07 UTC (permalink / raw)
  To: linux-mtd, Boris Brezillon, Brian Norris, Cyrille Pitchen,
	David Woodhouse, Marek Vasut, Richard Weinberger
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jan 2018 14:07:31 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/mtd/rfd_ftl.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index d1cbf26db2c0..efff25f15d5b 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -190,11 +190,8 @@ static int scan_header(struct partition *part)
 		goto err;
 
 	part->sector_map = vmalloc(part->sector_count * sizeof(u_long));
-	if (!part->sector_map) {
-		printk(KERN_ERR PREFIX "'%s': unable to allocate memory for "
-			"sector map", part->mbd.mtd->name);
+	if (!part->sector_map)
 		goto err;
-	}
 
 	for (i=0; i<part->sector_count; i++)
 		part->sector_map[i] = -1;
-- 
2.15.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/5] mtd/rfd_ftl: Less function calls in scan_header() after error detection
  2018-01-06 15:06 [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations SF Markus Elfring
  2018-01-06 15:07 ` [PATCH 1/5] mtd/rfd_ftl: Delete an error message for a failed memory allocation in scan_header() SF Markus Elfring
@ 2018-01-06 15:08 ` SF Markus Elfring
  2018-01-06 15:09 ` [PATCH 3/5] mtd/rfd_ftl: Improve a size determination in two functions SF Markus Elfring
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-01-06 15:08 UTC (permalink / raw)
  To: linux-mtd, Boris Brezillon, Brian Norris, Cyrille Pitchen,
	David Woodhouse, Marek Vasut, Richard Weinberger
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jan 2018 14:50:58 +0100

The functions "kfree" and "vfree" were called in three cases
by the scan_header() function during error handling even if
the passed data structure member contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/mtd/rfd_ftl.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index efff25f15d5b..19e14f909dc6 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -182,16 +182,16 @@ static int scan_header(struct partition *part)
 
 	part->header_cache = kmalloc(part->header_size, GFP_KERNEL);
 	if (!part->header_cache)
-		goto err;
+		return -ENOMEM;
 
 	part->blocks = kcalloc(part->total_blocks, sizeof(struct block),
 			GFP_KERNEL);
 	if (!part->blocks)
-		goto err;
+		goto free_cache;
 
 	part->sector_map = vmalloc(part->sector_count * sizeof(u_long));
 	if (!part->sector_map)
-		goto err;
+		goto free_blocks;
 
 	for (i=0; i<part->sector_count; i++)
 		part->sector_map[i] = -1;
@@ -229,9 +229,10 @@ static int scan_header(struct partition *part)
 
 err:
 	vfree(part->sector_map);
-	kfree(part->header_cache);
+free_blocks:
 	kfree(part->blocks);
-
+free_cache:
+	kfree(part->header_cache);
 	return rc;
 }
 
-- 
2.15.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/5] mtd/rfd_ftl: Improve a size determination in two functions
  2018-01-06 15:06 [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations SF Markus Elfring
  2018-01-06 15:07 ` [PATCH 1/5] mtd/rfd_ftl: Delete an error message for a failed memory allocation in scan_header() SF Markus Elfring
  2018-01-06 15:08 ` [PATCH 2/5] mtd/rfd_ftl: Less function calls in scan_header() after error detection SF Markus Elfring
@ 2018-01-06 15:09 ` SF Markus Elfring
  2018-01-06 15:10 ` [PATCH 4/5] mtd/rfd_ftl: Return directly after a failed kmalloc() in erase_block() SF Markus Elfring
  2018-01-06 15:11 ` [PATCH 5/5] mtd/rfd_ftl: Add some spaces for better code readability SF Markus Elfring
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-01-06 15:09 UTC (permalink / raw)
  To: linux-mtd, Boris Brezillon, Brian Norris, Cyrille Pitchen,
	David Woodhouse, Marek Vasut, Richard Weinberger
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jan 2018 15:03:29 +0100

Replace the specification of 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.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/mtd/rfd_ftl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 19e14f909dc6..dcf1b88e1193 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -323,10 +323,9 @@ static void erase_callback(struct erase_info *erase)
 
 static int erase_block(struct partition *part, int block)
 {
-	struct erase_info *erase;
 	int rc = -ENOMEM;
+	struct erase_info *erase = kmalloc(sizeof(*erase), GFP_KERNEL);
 
-	erase = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
 	if (!erase)
 		goto err;
 
@@ -759,7 +758,7 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	if (mtd->type != MTD_NORFLASH || mtd->size > UINT_MAX)
 		return;
 
-	part = kzalloc(sizeof(struct partition), GFP_KERNEL);
+	part = kzalloc(sizeof(*part), GFP_KERNEL);
 	if (!part)
 		return;
 
-- 
2.15.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/5] mtd/rfd_ftl: Return directly after a failed kmalloc() in erase_block()
  2018-01-06 15:06 [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2018-01-06 15:09 ` [PATCH 3/5] mtd/rfd_ftl: Improve a size determination in two functions SF Markus Elfring
@ 2018-01-06 15:10 ` SF Markus Elfring
  2018-01-06 15:11 ` [PATCH 5/5] mtd/rfd_ftl: Add some spaces for better code readability SF Markus Elfring
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-01-06 15:10 UTC (permalink / raw)
  To: linux-mtd, Boris Brezillon, Brian Norris, Cyrille Pitchen,
	David Woodhouse, Marek Vasut, Richard Weinberger
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jan 2018 15:18:28 +0100

* Return directly after a call of the function "kmalloc" failed
  at the beginning.

* Delete an initialisation for the variable "rc" and the jump label "err"
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/mtd/rfd_ftl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index dcf1b88e1193..e3155ec4be64 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -323,11 +323,11 @@ static void erase_callback(struct erase_info *erase)
 
 static int erase_block(struct partition *part, int block)
 {
-	int rc = -ENOMEM;
+	int rc;
 	struct erase_info *erase = kmalloc(sizeof(*erase), GFP_KERNEL);
 
 	if (!erase)
-		goto err;
+		return -ENOMEM;
 
 	erase->mtd = part->mbd.mtd;
 	erase->callback = erase_callback;
@@ -346,8 +346,6 @@ static int erase_block(struct partition *part, int block)
 				(unsigned long long)erase->len, part->mbd.mtd->name);
 		kfree(erase);
 	}
-
-err:
 	return rc;
 }
 
-- 
2.15.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/5] mtd/rfd_ftl: Add some spaces for better code readability
  2018-01-06 15:06 [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations SF Markus Elfring
                   ` (3 preceding siblings ...)
  2018-01-06 15:10 ` [PATCH 4/5] mtd/rfd_ftl: Return directly after a failed kmalloc() in erase_block() SF Markus Elfring
@ 2018-01-06 15:11 ` SF Markus Elfring
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-01-06 15:11 UTC (permalink / raw)
  To: linux-mtd, Boris Brezillon, Brian Norris, Cyrille Pitchen,
	David Woodhouse, Marek Vasut, Richard Weinberger
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jan 2018 15:47:01 +0100

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/mtd/rfd_ftl.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index e3155ec4be64..b6cc3690b9ed 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -103,7 +103,7 @@ static int build_block_map(struct partition *part, int block_no)
 
 	block->state = BLOCK_OK;
 
-	for (i=0; i<part->data_sectors_per_block; i++) {
+	for (i = 0; i < part->data_sectors_per_block; i++) {
 		u16 entry;
 
 		entry = le16_to_cpu(part->header_cache[HEADER_MAP_OFFSET + i]);
@@ -193,10 +193,10 @@ static int scan_header(struct partition *part)
 	if (!part->sector_map)
 		goto free_blocks;
 
-	for (i=0; i<part->sector_count; i++)
+	for (i = 0; i < part->sector_count; i++)
 		part->sector_map[i] = -1;
 
-	for (i=0, blocks_found=0; i<part->total_blocks; i++) {
+	for (i = 0, blocks_found = 0; i < part->total_blocks; i++) {
 		rc = mtd_read(part->mbd.mtd, i * part->block_size,
 			      part->header_size, &retlen,
 			      (u_char *)part->header_cache);
@@ -380,7 +380,7 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
 		goto err;
 	}
 
-	for (i=0; i<part->data_sectors_per_block; i++) {
+	for (i = 0; i < part->data_sectors_per_block; i++) {
 		u16 entry = le16_to_cpu(map[HEADER_MAP_OFFSET + i]);
 		u_long addr;
 
@@ -452,7 +452,7 @@ static int reclaim_block(struct partition *part, u_long *old_sector)
 	else
 		old_sector_block = -1;
 
-	for (block=0; block<part->total_blocks; block++) {
+	for (block = 0; block < part->total_blocks; block++) {
 		int this_score;
 
 		if (block == part->reserved_block)
@@ -625,8 +625,7 @@ static int find_free_sector(const struct partition *part, const struct block *bl
 
 		if (++i == part->data_sectors_per_block)
 			i = 0;
-	}
-	while(i != stop);
+	} while (i != stop);
 
 	return -1;
 }
@@ -718,7 +717,7 @@ static int rfd_ftl_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *
 
 	old_addr = part->sector_map[sector];
 
-	for (i=0; i<SECTOR_SIZE; i++) {
+	for (i = 0; i < SECTOR_SIZE; i++) {
 		if (!buf[i])
 			continue;
 
@@ -799,10 +798,9 @@ static void rfd_ftl_remove_dev(struct mtd_blktrans_dev *dev)
 	struct partition *part = (struct partition*)dev;
 	int i;
 
-	for (i=0; i<part->total_blocks; i++) {
+	for (i = 0; i < part->total_blocks; i++)
 		pr_debug("rfd_ftl_remove_dev:'%s': erase unit #%02d: %d erases\n",
 			part->mbd.mtd->name, i, part->blocks[i].erases);
-	}
 
 	del_mtd_blktrans_dev(dev);
 	vfree(part->sector_map);
-- 
2.15.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-06 15:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-06 15:06 [PATCH 0/5] mtd/rfd_ftl: Adjustments for some function implementations SF Markus Elfring
2018-01-06 15:07 ` [PATCH 1/5] mtd/rfd_ftl: Delete an error message for a failed memory allocation in scan_header() SF Markus Elfring
2018-01-06 15:08 ` [PATCH 2/5] mtd/rfd_ftl: Less function calls in scan_header() after error detection SF Markus Elfring
2018-01-06 15:09 ` [PATCH 3/5] mtd/rfd_ftl: Improve a size determination in two functions SF Markus Elfring
2018-01-06 15:10 ` [PATCH 4/5] mtd/rfd_ftl: Return directly after a failed kmalloc() in erase_block() SF Markus Elfring
2018-01-06 15:11 ` [PATCH 5/5] mtd/rfd_ftl: Add some spaces for better code readability SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome