All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/ntfs3: Use linux/log2 is_power_of_2 function
@ 2021-08-16 10:37 Kari Argillander
  2021-08-27 16:08 ` Konstantin Komarov
  0 siblings, 1 reply; 2+ messages in thread
From: Kari Argillander @ 2021-08-16 10:37 UTC (permalink / raw)
  To: Konstantin Komarov, ntfs3; +Cc: Kari Argillander, linux-kernel, linux-fsdevel

We do not need our own implementation for this function in this
driver. It is much better to use generic one.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
---
 fs/ntfs3/ntfs_fs.h | 5 -----
 fs/ntfs3/run.c     | 3 ++-
 fs/ntfs3/super.c   | 9 +++++----
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index 0c3ac89c3115..c8ea6dd38c21 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -972,11 +972,6 @@ static inline struct buffer_head *ntfs_bread(struct super_block *sb,
 	return NULL;
 }
 
-static inline bool is_power_of2(size_t v)
-{
-	return v && !(v & (v - 1));
-}
-
 static inline struct ntfs_inode *ntfs_i(struct inode *inode)
 {
 	return container_of(inode, struct ntfs_inode, vfs_inode);
diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c
index 5cdf6efe67e0..ce6bff3568df 100644
--- a/fs/ntfs3/run.c
+++ b/fs/ntfs3/run.c
@@ -9,6 +9,7 @@
 #include <linux/blkdev.h>
 #include <linux/buffer_head.h>
 #include <linux/fs.h>
+#include <linux/log2.h>
 #include <linux/nls.h>
 
 #include "debug.h"
@@ -376,7 +377,7 @@ bool run_add_entry(struct runs_tree *run, CLST vcn, CLST lcn, CLST len,
 			if (!used) {
 				bytes = 64;
 			} else if (used <= 16 * PAGE_SIZE) {
-				if (is_power_of2(run->allocated))
+				if (is_power_of_2(run->allocated))
 					bytes = run->allocated << 1;
 				else
 					bytes = (size_t)1
diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 6be13e256c1a..c1b7127f5e61 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -29,6 +29,7 @@
 #include <linux/exportfs.h>
 #include <linux/fs.h>
 #include <linux/iversion.h>
+#include <linux/log2.h>
 #include <linux/module.h>
 #include <linux/nls.h>
 #include <linux/parser.h>
@@ -735,13 +736,13 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
 
 	boot_sector_size = (u32)boot->bytes_per_sector[1] << 8;
 	if (boot->bytes_per_sector[0] || boot_sector_size < SECTOR_SIZE ||
-	    !is_power_of2(boot_sector_size)) {
+	    !is_power_of_2(boot_sector_size)) {
 		goto out;
 	}
 
 	/* cluster size: 512, 1K, 2K, 4K, ... 2M */
 	sct_per_clst = true_sectors_per_clst(boot);
-	if (!is_power_of2(sct_per_clst))
+	if (!is_power_of_2(sct_per_clst))
 		goto out;
 
 	mlcn = le64_to_cpu(boot->mft_clst);
@@ -757,14 +758,14 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
 	/* Check MFT record size */
 	if ((boot->record_size < 0 &&
 	     SECTOR_SIZE > (2U << (-boot->record_size))) ||
-	    (boot->record_size >= 0 && !is_power_of2(boot->record_size))) {
+	    (boot->record_size >= 0 && !is_power_of_2(boot->record_size))) {
 		goto out;
 	}
 
 	/* Check index record size */
 	if ((boot->index_size < 0 &&
 	     SECTOR_SIZE > (2U << (-boot->index_size))) ||
-	    (boot->index_size >= 0 && !is_power_of2(boot->index_size))) {
+	    (boot->index_size >= 0 && !is_power_of_2(boot->index_size))) {
 		goto out;
 	}
 
-- 
2.30.2


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

* RE: [PATCH] fs/ntfs3: Use linux/log2 is_power_of_2 function
  2021-08-16 10:37 [PATCH] fs/ntfs3: Use linux/log2 is_power_of_2 function Kari Argillander
@ 2021-08-27 16:08 ` Konstantin Komarov
  0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Komarov @ 2021-08-27 16:08 UTC (permalink / raw)
  To: Kari Argillander, ntfs3; +Cc: linux-kernel, linux-fsdevel

> From: Kari Argillander <kari.argillander@gmail.com>
> Sent: Monday, August 16, 2021 1:38 PM
> To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>; ntfs3@lists.linux.dev
> Cc: Kari Argillander <kari.argillander@gmail.com>; linux-kernel@vger.kernel.org; linux-fsdevel@vger.kernel.org
> Subject: [PATCH] fs/ntfs3: Use linux/log2 is_power_of_2 function
> 
> We do not need our own implementation for this function in this
> driver. It is much better to use generic one.
> 
> Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
> ---
>  fs/ntfs3/ntfs_fs.h | 5 -----
>  fs/ntfs3/run.c     | 3 ++-
>  fs/ntfs3/super.c   | 9 +++++----
>  3 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
> index 0c3ac89c3115..c8ea6dd38c21 100644
> --- a/fs/ntfs3/ntfs_fs.h
> +++ b/fs/ntfs3/ntfs_fs.h
> @@ -972,11 +972,6 @@ static inline struct buffer_head *ntfs_bread(struct super_block *sb,
>  	return NULL;
>  }
> 
> -static inline bool is_power_of2(size_t v)
> -{
> -	return v && !(v & (v - 1));
> -}
> -
>  static inline struct ntfs_inode *ntfs_i(struct inode *inode)
>  {
>  	return container_of(inode, struct ntfs_inode, vfs_inode);
> diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c
> index 5cdf6efe67e0..ce6bff3568df 100644
> --- a/fs/ntfs3/run.c
> +++ b/fs/ntfs3/run.c
> @@ -9,6 +9,7 @@
>  #include <linux/blkdev.h>
>  #include <linux/buffer_head.h>
>  #include <linux/fs.h>
> +#include <linux/log2.h>
>  #include <linux/nls.h>
> 
>  #include "debug.h"
> @@ -376,7 +377,7 @@ bool run_add_entry(struct runs_tree *run, CLST vcn, CLST lcn, CLST len,
>  			if (!used) {
>  				bytes = 64;
>  			} else if (used <= 16 * PAGE_SIZE) {
> -				if (is_power_of2(run->allocated))
> +				if (is_power_of_2(run->allocated))
>  					bytes = run->allocated << 1;
>  				else
>  					bytes = (size_t)1
> diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
> index 6be13e256c1a..c1b7127f5e61 100644
> --- a/fs/ntfs3/super.c
> +++ b/fs/ntfs3/super.c
> @@ -29,6 +29,7 @@
>  #include <linux/exportfs.h>
>  #include <linux/fs.h>
>  #include <linux/iversion.h>
> +#include <linux/log2.h>
>  #include <linux/module.h>
>  #include <linux/nls.h>
>  #include <linux/parser.h>
> @@ -735,13 +736,13 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
> 
>  	boot_sector_size = (u32)boot->bytes_per_sector[1] << 8;
>  	if (boot->bytes_per_sector[0] || boot_sector_size < SECTOR_SIZE ||
> -	    !is_power_of2(boot_sector_size)) {
> +	    !is_power_of_2(boot_sector_size)) {
>  		goto out;
>  	}
> 
>  	/* cluster size: 512, 1K, 2K, 4K, ... 2M */
>  	sct_per_clst = true_sectors_per_clst(boot);
> -	if (!is_power_of2(sct_per_clst))
> +	if (!is_power_of_2(sct_per_clst))
>  		goto out;
> 
>  	mlcn = le64_to_cpu(boot->mft_clst);
> @@ -757,14 +758,14 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
>  	/* Check MFT record size */
>  	if ((boot->record_size < 0 &&
>  	     SECTOR_SIZE > (2U << (-boot->record_size))) ||
> -	    (boot->record_size >= 0 && !is_power_of2(boot->record_size))) {
> +	    (boot->record_size >= 0 && !is_power_of_2(boot->record_size))) {
>  		goto out;
>  	}
> 
>  	/* Check index record size */
>  	if ((boot->index_size < 0 &&
>  	     SECTOR_SIZE > (2U << (-boot->index_size))) ||
> -	    (boot->index_size >= 0 && !is_power_of2(boot->index_size))) {
> +	    (boot->index_size >= 0 && !is_power_of_2(boot->index_size))) {
>  		goto out;
>  	}
> 
> --
> 2.30.2

Hi Kari! Thanks for the patch, applied.

Best regards.

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

end of thread, other threads:[~2021-08-27 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 10:37 [PATCH] fs/ntfs3: Use linux/log2 is_power_of_2 function Kari Argillander
2021-08-27 16:08 ` Konstantin Komarov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.