Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1297576

[PATCH 4/5] block-LDM: Less function calls in ldm_validate_privheads() after error detection

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 4/5] block-LDM: Less function calls in ldm_validate_privheads() after error detection
Date 2015-12-23 19:20 +0100
Message-ID <qIWb0-4BV-13@gated-at.bofh.it> (permalink)
References <qEuGl-43C-5@gated-at.bofh.it> <qIOds-7UY-5@gated-at.bofh.it> <qIP9v-8u4-7@gated-at.bofh.it> <qIW1k-4yL-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 23 Dec 2015 14:31:01 +0100

The kfree() function was called by the ldm_validate_privheads() function
during error handling even if the passed variable "ph" contained
a null pointer.

* Corresponding implementation details could be improved by adjustments
  for jump targets according to the Linux coding style convention.

* The variable "result" will eventually be set to an appropriate value.
  Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 block/partitions/ldm.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index 3118d24..6fc9150 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -335,16 +335,20 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
 	struct privhead *ph[3] = { ph1 };
 	Sector sect;
 	u8 *data;
-	bool result = false;
+	bool result;
 	long num_sects;
 	int i;
 
 	BUG_ON (!state || !ph1);
 
 	ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
+	if (!ph[1])
+		return false;
 	ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
-	if (!ph[1] || !ph[2])
-		goto out;
+	if (!ph[2]) {
+		result = false;
+		goto free_a_head;
+	}
 
 	/* off[1 & 2] are relative to ph[0]->config_start */
 	ph[0]->config_start = 0;
@@ -355,14 +359,15 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
 					&sect);
 		if (!data) {
 			ldm_crit ("Disk read failed.");
-			goto out;
+			result = false;
+			goto free_another_head;
 		}
 		result = ldm_parse_privhead (data, ph[i]);
 		put_dev_sector (sect);
 		if (!result) {
 			ldm_error ("Cannot find PRIVHEAD %d.", i+1); /* Log again */
 			if (i < 2)
-				goto out;	/* Already logged */
+				goto free_another_head;	/* Already logged */
 			else
 				break;	/* FIXME ignore for now, 3rd PH can fail on odd-sized disks */
 		}
@@ -373,30 +378,31 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
 	if ((ph[0]->config_start > num_sects) ||
 	   ((ph[0]->config_start + ph[0]->config_size) > num_sects)) {
 		ldm_crit ("Database extends beyond the end of the disk.");
-		goto out;
+		goto free_another_head;
 	}
 
 	if ((ph[0]->logical_disk_start > ph[0]->config_start) ||
 	   ((ph[0]->logical_disk_start + ph[0]->logical_disk_size)
 		    > ph[0]->config_start)) {
 		ldm_crit ("Disk and database overlap.");
-		goto out;
+		goto free_another_head;
 	}
 
 	if (!ldm_compare_privheads (ph[0], ph[1])) {
 		ldm_crit ("Primary and backup PRIVHEADs don't match.");
-		goto out;
+		goto free_another_head;
 	}
 	/* FIXME ignore this for now
 	if (!ldm_compare_privheads (ph[0], ph[2])) {
 		ldm_crit ("Primary and backup PRIVHEADs don't match.");
-		goto out;
+		goto free_another_head;
 	}*/
 	ldm_debug ("Validated PRIVHEADs successfully.");
 	result = true;
-out:
-	kfree (ph[1]);
-	kfree (ph[2]);
+free_another_head:
+	kfree(ph[2]);
+free_a_head:
+	kfree(ph[1]);
 	return result;
 }
 
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH] block-LDM: One function call less in ldm_validate_tocblocks()  after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 10:50 +0100
  Re: [PATCH] block-LDM: One function call less in ldm_validate_tocblocks()  after error detection Julia Lawall <julia.lawall@lip6.fr> - 2015-12-23 11:50 +0100
    [PATCH 0/5] block-LDM: Improvements for exception handling SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 19:10 +0100
      [PATCH 1/5] block-LDM: One function call less in  ldm_validate_tocblocks() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 19:10 +0100
      [PATCH 2/5] block-LDM: Delete extra log messages for memory  allocation failures SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 19:10 +0100
      [PATCH 3/5] block-LDM: One function call less in ldm_partition()  after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 19:20 +0100
      [PATCH 5/5] block-LDM: Fine-tuning for the source code formatting SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 19:20 +0100
      [PATCH 4/5] block-LDM: Less function calls in  ldm_validate_privheads() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2015-12-23 19:20 +0100

csiph-web