Commit 304c4c84 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] jbd: avoid kfree(NULL)

There are a couple of places where JBD has to check to see whether an unneeded
memory allocation was performed.  Usually it _was_ needed, so we end up
calling kfree(NULL).  We can micro-optimise that by checking the pointer
before calling kfree().

Thanks to Steven Rostedt <rostedt@goodmis.org> for identifying this.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 22722051
...@@ -227,6 +227,7 @@ static int start_this_handle(journal_t *journal, handle_t *handle) ...@@ -227,6 +227,7 @@ static int start_this_handle(journal_t *journal, handle_t *handle)
spin_unlock(&transaction->t_handle_lock); spin_unlock(&transaction->t_handle_lock);
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
out: out:
if (unlikely(new_transaction)) /* It's usually NULL */
kfree(new_transaction); kfree(new_transaction);
return ret; return ret;
} }
...@@ -724,6 +725,7 @@ do_get_write_access(handle_t *handle, struct journal_head *jh, ...@@ -724,6 +725,7 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
journal_cancel_revoke(handle, jh); journal_cancel_revoke(handle, jh);
out: out:
if (unlikely(frozen_buffer)) /* It's usually NULL */
kfree(frozen_buffer); kfree(frozen_buffer);
JBUFFER_TRACE(jh, "exit"); JBUFFER_TRACE(jh, "exit");
...@@ -903,6 +905,7 @@ int journal_get_undo_access(handle_t *handle, struct buffer_head *bh) ...@@ -903,6 +905,7 @@ int journal_get_undo_access(handle_t *handle, struct buffer_head *bh)
jbd_unlock_bh_state(bh); jbd_unlock_bh_state(bh);
out: out:
journal_put_journal_head(jh); journal_put_journal_head(jh);
if (unlikely(committed_data))
kfree(committed_data); kfree(committed_data);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment