Patchwork fs/jbd: set pointer = NULL, after kfree it.

login
register
mail settings
Submitter Chen Gang
Date Dec. 24, 2012, 2:39 a.m.
Message ID <50D7C04B.6010109@asianux.com>
Download mbox | patch
Permalink /patch/208016/
State Not Applicable
Headers show

Comments

Chen Gang - Dec. 24, 2012, 2:39 a.m.
set pointer = NULL, after call journal_destroy_revoke_table.
    in journal_destroy_revoke_table, it will call kfree to free the buffer.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 fs/jbd/revoke.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Jan Kara - Dec. 31, 2012, 3:23 p.m.
On Mon 24-12-12 10:39:07, Chen Gang wrote:
> 
>   set pointer = NULL, after call journal_destroy_revoke_table.
>     in journal_destroy_revoke_table, it will call kfree to free the buffer.
  The journal structure will get freed immediately after we return from
journal_init_revoke() (in case it failed) or journal_destroy_revoke() so I
don't see a point in setting the pointers to NULL. Or do I miss something?

								Honza
> 
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
>  fs/jbd/revoke.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
> index 25c713e..d6457b0 100644
> --- a/fs/jbd/revoke.c
> +++ b/fs/jbd/revoke.c
> @@ -295,6 +295,7 @@ int journal_init_revoke(journal_t *journal, int hash_size)
>  
>  fail1:
>  	journal_destroy_revoke_table(journal->j_revoke_table[0]);
> +	journal->j_revoke_table[0] = NULL;
>  fail0:
>  	return -ENOMEM;
>  }
> @@ -303,10 +304,14 @@ fail0:
>  void journal_destroy_revoke(journal_t *journal)
>  {
>  	journal->j_revoke = NULL;
> -	if (journal->j_revoke_table[0])
> +	if (journal->j_revoke_table[0]) {
>  		journal_destroy_revoke_table(journal->j_revoke_table[0]);
> -	if (journal->j_revoke_table[1])
> +		journal->j_revoke_table[0] = NULL;
> +	}
> +	if (journal->j_revoke_table[1]) {
>  		journal_destroy_revoke_table(journal->j_revoke_table[1]);
> +		journal->j_revoke_table[1] = NULL;
> +	}
>  }
>  
>  
> -- 
> 1.7.10.4

Patch

diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
index 25c713e..d6457b0 100644
--- a/fs/jbd/revoke.c
+++ b/fs/jbd/revoke.c
@@ -295,6 +295,7 @@  int journal_init_revoke(journal_t *journal, int hash_size)
 
 fail1:
 	journal_destroy_revoke_table(journal->j_revoke_table[0]);
+	journal->j_revoke_table[0] = NULL;
 fail0:
 	return -ENOMEM;
 }
@@ -303,10 +304,14 @@  fail0:
 void journal_destroy_revoke(journal_t *journal)
 {
 	journal->j_revoke = NULL;
-	if (journal->j_revoke_table[0])
+	if (journal->j_revoke_table[0]) {
 		journal_destroy_revoke_table(journal->j_revoke_table[0]);
-	if (journal->j_revoke_table[1])
+		journal->j_revoke_table[0] = NULL;
+	}
+	if (journal->j_revoke_table[1]) {
 		journal_destroy_revoke_table(journal->j_revoke_table[1]);
+		journal->j_revoke_table[1] = NULL;
+	}
 }