mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] fs/jbd/revoke.c: replace shift loop by ilog2
@ 2014-05-20 16:50 Fabian Frederick
  2014-05-20 16:56 ` Joe Perches
  2014-05-21  8:28 ` Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: Fabian Frederick @ 2014-05-20 16:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: jack, akpm, Joe Perches

journal_init_revoke_table is only called with positive hash_size
(JOURNAL_REVOKE_DEFAULT_HASH) so we can replace loop shift by ilog2

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/jbd/revoke.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
index 25c713e..8898bbd 100644
--- a/fs/jbd/revoke.c
+++ b/fs/jbd/revoke.c
@@ -231,19 +231,15 @@ record_cache_failure:
 
 static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)
 {
-	int shift = 0;
-	int tmp = hash_size;
+	int i;
 	struct jbd_revoke_table_s *table;
 
 	table = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
 	if (!table)
 		goto out;
 
-	while((tmp >>= 1UL) != 0UL)
-		shift++;
-
 	table->hash_size = hash_size;
-	table->hash_shift = shift;
+	table->hash_shift = ilog2(hash_size);
 	table->hash_table =
 		kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
 	if (!table->hash_table) {
@@ -252,8 +248,8 @@ static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)
 		goto out;
 	}
 
-	for (tmp = 0; tmp < hash_size; tmp++)
-		INIT_LIST_HEAD(&table->hash_table[tmp]);
+	for (i = 0; i < hash_size; i++)
+		INIT_LIST_HEAD(&table->hash_table[i]);
 
 out:
 	return table;
-- 
1.8.4.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] fs/jbd/revoke.c: replace shift loop by ilog2
  2014-05-20 16:50 [PATCH 1/1] fs/jbd/revoke.c: replace shift loop by ilog2 Fabian Frederick
@ 2014-05-20 16:56 ` Joe Perches
  2014-05-21  8:28 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2014-05-20 16:56 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: linux-kernel, jack, akpm

On Tue, 2014-05-20 at 18:50 +0200, Fabian Frederick wrote:
> journal_init_revoke_table is only called with positive hash_size
> (JOURNAL_REVOKE_DEFAULT_HASH) so we can replace loop shift by ilog2

This commit message is lacking something like:

Also replace index variable tmp with the more commonly used i.

> diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
[]
> @@ -231,19 +231,15 @@ record_cache_failure:
>  
>  static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)
>  {
> -	int shift = 0;
> -	int tmp = hash_size;
> +	int i;
>  	struct jbd_revoke_table_s *table;
>  
>  	table = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
>  	if (!table)
>  		goto out;
>  
> -	while((tmp >>= 1UL) != 0UL)
> -		shift++;
> -
>  	table->hash_size = hash_size;
> -	table->hash_shift = shift;
> +	table->hash_shift = ilog2(hash_size);
>  	table->hash_table =
>  		kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
>  	if (!table->hash_table) {
> @@ -252,8 +248,8 @@ static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)
>  		goto out;
>  	}
>  
> -	for (tmp = 0; tmp < hash_size; tmp++)
> -		INIT_LIST_HEAD(&table->hash_table[tmp]);
> +	for (i = 0; i < hash_size; i++)
> +		INIT_LIST_HEAD(&table->hash_table[i]);
>  
>  out:
>  	return table;




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] fs/jbd/revoke.c: replace shift loop by ilog2
  2014-05-20 16:50 [PATCH 1/1] fs/jbd/revoke.c: replace shift loop by ilog2 Fabian Frederick
  2014-05-20 16:56 ` Joe Perches
@ 2014-05-21  8:28 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2014-05-21  8:28 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: linux-kernel, jack, akpm, Joe Perches

On Tue 20-05-14 18:50:16, Fabian Frederick wrote:
> journal_init_revoke_table is only called with positive hash_size
> (JOURNAL_REVOKE_DEFAULT_HASH) so we can replace loop shift by ilog2
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Joe Perches <joe@perches.com>
> Signed-off-by: Fabian Frederick <fabf@skynet.be>
  Thanks. I've merged the patch to my tree.

								Honza
> ---
>  fs/jbd/revoke.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
> index 25c713e..8898bbd 100644
> --- a/fs/jbd/revoke.c
> +++ b/fs/jbd/revoke.c
> @@ -231,19 +231,15 @@ record_cache_failure:
>  
>  static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)
>  {
> -	int shift = 0;
> -	int tmp = hash_size;
> +	int i;
>  	struct jbd_revoke_table_s *table;
>  
>  	table = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
>  	if (!table)
>  		goto out;
>  
> -	while((tmp >>= 1UL) != 0UL)
> -		shift++;
> -
>  	table->hash_size = hash_size;
> -	table->hash_shift = shift;
> +	table->hash_shift = ilog2(hash_size);
>  	table->hash_table =
>  		kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
>  	if (!table->hash_table) {
> @@ -252,8 +248,8 @@ static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)
>  		goto out;
>  	}
>  
> -	for (tmp = 0; tmp < hash_size; tmp++)
> -		INIT_LIST_HEAD(&table->hash_table[tmp]);
> +	for (i = 0; i < hash_size; i++)
> +		INIT_LIST_HEAD(&table->hash_table[i]);
>  
>  out:
>  	return table;
> -- 
> 1.8.4.5
> 
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-21  8:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-20 16:50 [PATCH 1/1] fs/jbd/revoke.c: replace shift loop by ilog2 Fabian Frederick
2014-05-20 16:56 ` Joe Perches
2014-05-21  8:28 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®