linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations
       [not found] <566ABCD9.1060404@users.sourceforge.net>
@ 2015-12-31 20:21 ` SF Markus Elfring
  2015-12-31 20:25   ` [PATCH 1/3] mtd-rfd_ftl: Replace a variable initialisation by assignments in move_block_contents() SF Markus Elfring
                     ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-31 20:21 UTC (permalink / raw)
  To: linux-mtd, Brian Norris, David Woodhouse
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 31 Dec 2015 21:15:15 +0100

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

Markus Elfring (3):
  Replace a variable initialisation by assignments
  Refactoring for move_block_contents()
  Refactoring for erase_block()

 drivers/mtd/rfd_ftl.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

-- 
2.6.3

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

* [PATCH 1/3] mtd-rfd_ftl: Replace a variable initialisation by assignments in move_block_contents()
  2015-12-31 20:21 ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations SF Markus Elfring
@ 2015-12-31 20:25   ` SF Markus Elfring
  2015-12-31 20:26   ` [PATCH 2/3] mtd-rfd_ftl: Refactoring for move_block_contents() SF Markus Elfring
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-31 20:25 UTC (permalink / raw)
  To: linux-mtd, Brian Norris, David Woodhouse
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 31 Dec 2015 20:34:51 +0100

Replace an explicit initialisation for the variable "rc" at the beginning
by assignments that will only be performed if a memory allocation failed.

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

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index d1cbf26..2927e1b 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -359,17 +359,21 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
 	void *sector_data;
 	u16 *map;
 	size_t retlen;
-	int i, rc = -ENOMEM;
+	int i, rc;
 
 	part->is_reclaiming = 1;
 
 	sector_data = kmalloc(SECTOR_SIZE, GFP_KERNEL);
-	if (!sector_data)
+	if (!sector_data) {
+		rc = -ENOMEM;
 		goto err3;
+	}
 
 	map = kmalloc(part->header_size, GFP_KERNEL);
-	if (!map)
+	if (!map) {
+		rc = -ENOMEM;
 		goto err2;
+	}
 
 	rc = mtd_read(part->mbd.mtd, part->blocks[block_no].offset,
 		      part->header_size, &retlen, (u_char *)map);
-- 
2.6.3

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

* [PATCH 2/3] mtd-rfd_ftl: Refactoring for move_block_contents()
  2015-12-31 20:21 ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations SF Markus Elfring
  2015-12-31 20:25   ` [PATCH 1/3] mtd-rfd_ftl: Replace a variable initialisation by assignments in move_block_contents() SF Markus Elfring
@ 2015-12-31 20:26   ` SF Markus Elfring
  2015-12-31 20:27   ` [PATCH 3/3] mtd-rfd_ftl: Refactoring for erase_block() SF Markus Elfring
  2016-01-05  0:13   ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations Brian Norris
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-31 20:26 UTC (permalink / raw)
  To: linux-mtd, Brian Norris, David Woodhouse
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 31 Dec 2015 20:54:50 +0100

This issue was detected by using the Coccinelle software.

Rename jump labels according to the current Linux coding style convention.

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

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 2927e1b..9b59423 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -366,13 +366,13 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
 	sector_data = kmalloc(SECTOR_SIZE, GFP_KERNEL);
 	if (!sector_data) {
 		rc = -ENOMEM;
-		goto err3;
+		goto reset_reclaim;
 	}
 
 	map = kmalloc(part->header_size, GFP_KERNEL);
 	if (!map) {
 		rc = -ENOMEM;
-		goto err2;
+		goto free_sector;
 	}
 
 	rc = mtd_read(part->mbd.mtd, part->blocks[block_no].offset,
@@ -385,8 +385,7 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
 		printk(KERN_ERR PREFIX "error reading '%s' at "
 			"0x%lx\n", part->mbd.mtd->name,
 			part->blocks[block_no].offset);
-
-		goto err;
+		goto free_map;
 	}
 
 	for (i=0; i<part->data_sectors_per_block; i++) {
@@ -417,7 +416,6 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
 		}
 		rc = mtd_read(part->mbd.mtd, addr, SECTOR_SIZE, &retlen,
 			      sector_data);
-
 		if (!rc && retlen != SECTOR_SIZE)
 			rc = -EIO;
 
@@ -425,24 +423,20 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
 			printk(KERN_ERR PREFIX "'%s': Unable to "
 				"read sector for relocation\n",
 				part->mbd.mtd->name);
-
-			goto err;
+			goto free_map;
 		}
 
 		rc = rfd_ftl_writesect((struct mtd_blktrans_dev*)part,
 				entry, sector_data);
-
 		if (rc)
-			goto err;
+			goto free_map;
 	}
-
-err:
+free_map:
 	kfree(map);
-err2:
+free_sector:
 	kfree(sector_data);
-err3:
+reset_reclaim:
 	part->is_reclaiming = 0;
-
 	return rc;
 }
 
-- 
2.6.3

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

* [PATCH 3/3] mtd-rfd_ftl: Refactoring for erase_block()
  2015-12-31 20:21 ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations SF Markus Elfring
  2015-12-31 20:25   ` [PATCH 1/3] mtd-rfd_ftl: Replace a variable initialisation by assignments in move_block_contents() SF Markus Elfring
  2015-12-31 20:26   ` [PATCH 2/3] mtd-rfd_ftl: Refactoring for move_block_contents() SF Markus Elfring
@ 2015-12-31 20:27   ` SF Markus Elfring
  2016-01-05  0:13   ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations Brian Norris
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-31 20:27 UTC (permalink / raw)
  To: linux-mtd, Brian Norris, David Woodhouse
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 31 Dec 2015 21:06:27 +0100

This issue was detected by using the Coccinelle software.

* Return directly if a memory allocation failed.

* Drop the explicit initialisation for the variable "rc"
  at the beginning then.

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 9b59423..8379447 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -326,11 +326,11 @@ static void erase_callback(struct erase_info *erase)
 static int erase_block(struct partition *part, int block)
 {
 	struct erase_info *erase;
-	int rc = -ENOMEM;
+	int rc;
 
 	erase = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
 	if (!erase)
-		goto err;
+		return -ENOMEM;
 
 	erase->mtd = part->mbd.mtd;
 	erase->callback = erase_callback;
@@ -349,8 +349,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.6.3

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

* Re: [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations
  2015-12-31 20:21 ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations SF Markus Elfring
                     ` (2 preceding siblings ...)
  2015-12-31 20:27   ` [PATCH 3/3] mtd-rfd_ftl: Refactoring for erase_block() SF Markus Elfring
@ 2016-01-05  0:13   ` Brian Norris
  3 siblings, 0 replies; 5+ messages in thread
From: Brian Norris @ 2016-01-05  0:13 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-mtd, David Woodhouse, LKML, kernel-janitors, Julia Lawall

On Thu, Dec 31, 2015 at 09:21:14PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 31 Dec 2015 21:15:15 +0100
> 
> A few update suggestions were taken into account
> from static source code analysis.

Are you fixing anything? Have you tested your work?

At the moment, I can't find any value in your patches.

Brian

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

end of thread, other threads:[~2016-01-05  0:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-31 20:21 ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations SF Markus Elfring
2015-12-31 20:25   ` [PATCH 1/3] mtd-rfd_ftl: Replace a variable initialisation by assignments in move_block_contents() SF Markus Elfring
2015-12-31 20:26   ` [PATCH 2/3] mtd-rfd_ftl: Refactoring for move_block_contents() SF Markus Elfring
2015-12-31 20:27   ` [PATCH 3/3] mtd-rfd_ftl: Refactoring for erase_block() SF Markus Elfring
2016-01-05  0:13   ` [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).