From 304c4c841a31c780a45d65e389b07706babf5d36 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Fri, 23 Jun 2006 02:05:31 -0700 Subject: [PATCH] [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 for identifying this. Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/jbd/transaction.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c index ff75afe9b185..508b2ea91f43 100644 --- a/fs/jbd/transaction.c +++ b/fs/jbd/transaction.c @@ -227,7 +227,8 @@ static int start_this_handle(journal_t *journal, handle_t *handle) spin_unlock(&transaction->t_handle_lock); spin_unlock(&journal->j_state_lock); out: - kfree(new_transaction); + if (unlikely(new_transaction)) /* It's usually NULL */ + kfree(new_transaction); return ret; } @@ -724,7 +725,8 @@ do_get_write_access(handle_t *handle, struct journal_head *jh, journal_cancel_revoke(handle, jh); out: - kfree(frozen_buffer); + if (unlikely(frozen_buffer)) /* It's usually NULL */ + kfree(frozen_buffer); JBUFFER_TRACE(jh, "exit"); return error; @@ -903,7 +905,8 @@ int journal_get_undo_access(handle_t *handle, struct buffer_head *bh) jbd_unlock_bh_state(bh); out: journal_put_journal_head(jh); - kfree(committed_data); + if (unlikely(committed_data)) + kfree(committed_data); return err; } -- GitLab