Patchwork [1/2] UBIFS: make ubifs_lpt_init clean-up in case of failure

login
register
mail settings
Submitter Artem Bityutskiy
Date May 18, 2012, 11:32 a.m.
Message ID <1337340757-26127-1-git-send-email-dedekind1@gmail.com>
Download mbox | patch
Permalink /patch/160097/
State Accepted
Commit 499429760650018216eb8d0b35067cf2c5c4520b
Headers show

Comments

Artem Bityutskiy - May 18, 2012, 11:32 a.m.
From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

Most functions in UBIFS follow the following designn pattern: if the function
allocates multiple resources, and failss at some point, it frees what it has
allocated and returns an error. So the caller can rely on the fact that the
callee has cleaned up everything after own failure.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 fs/ubifs/lpt.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Sidney Amani - May 20, 2012, 5:49 a.m.
On Fri, May 18, 2012 at 9:32 PM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
>
> Most functions in UBIFS follow the following designn pattern: if the function
> allocates multiple resources, and failss at some point, it frees what it has
> allocated and returns an error. So the caller can rely on the fact that the
> callee has cleaned up everything after own failure.
>
> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

Acked-by: Sidney Amani <seed95@gmail.com>

Patch

diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 2054e81..b4280c4 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -1740,16 +1740,20 @@  int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr)
 	if (rd) {
 		err = lpt_init_rd(c);
 		if (err)
-			return err;
+			goto out_err;
 	}
 
 	if (wr) {
 		err = lpt_init_wr(c);
 		if (err)
-			return err;
+			goto out_err;
 	}
 
 	return 0;
+
+out_err:
+	ubifs_lpt_free(c, 0);
+	return err;
 }
 
 /**