* [PATCH] mtd: spi-nor: use is_power_of_2()
@ 2021-03-05 23:45 ` Michael Walle
0 siblings, 0 replies; 6+ messages in thread
From: Michael Walle @ 2021-03-05 23:45 UTC (permalink / raw)
To: linux-mtd, linux-kernel
Cc: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Michael Walle
There is already a function to check if an integer is a power of 2. Use
it.
Signed-off-by: Michael Walle <michael@walle.cc>
---
drivers/mtd/spi-nor/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0522304f52fa..4a315cb1c4db 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2336,11 +2336,8 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
* If page_size is a power of two, the offset can be quickly
* calculated with an AND operation. On the other cases we
* need to do a modulus operation (more expensive).
- * Power of two numbers have only one bit set and we can use
- * the instruction hweight32 to detect if we need to do a
- * modulus (do_div()) or not.
*/
- if (hweight32(nor->page_size) == 1) {
+ if (is_power_of_2(nor->page_size)) {
page_offset = addr & (nor->page_size - 1);
} else {
uint64_t aux = addr;
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] mtd: spi-nor: use is_power_of_2()
@ 2021-03-05 23:45 ` Michael Walle
0 siblings, 0 replies; 6+ messages in thread
From: Michael Walle @ 2021-03-05 23:45 UTC (permalink / raw)
To: linux-mtd, linux-kernel
Cc: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Michael Walle
There is already a function to check if an integer is a power of 2. Use
it.
Signed-off-by: Michael Walle <michael@walle.cc>
---
drivers/mtd/spi-nor/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0522304f52fa..4a315cb1c4db 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2336,11 +2336,8 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
* If page_size is a power of two, the offset can be quickly
* calculated with an AND operation. On the other cases we
* need to do a modulus operation (more expensive).
- * Power of two numbers have only one bit set and we can use
- * the instruction hweight32 to detect if we need to do a
- * modulus (do_div()) or not.
*/
- if (hweight32(nor->page_size) == 1) {
+ if (is_power_of_2(nor->page_size)) {
page_offset = addr & (nor->page_size - 1);
} else {
uint64_t aux = addr;
--
2.20.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: spi-nor: use is_power_of_2()
2021-03-05 23:45 ` Michael Walle
@ 2021-03-08 6:20 ` Tudor Ambarus
-1 siblings, 0 replies; 6+ messages in thread
From: Tudor Ambarus @ 2021-03-08 6:20 UTC (permalink / raw)
To: linux-kernel, linux-mtd, Michael Walle
Cc: Tudor Ambarus, Richard Weinberger, Miquel Raynal, Vignesh Raghavendra
On Sat, 6 Mar 2021 00:45:52 +0100, Michael Walle wrote:
> There is already a function to check if an integer is a power of 2. Use
> it.
Applied to spi-nor/next, thanks!
[1/1] mtd: spi-nor: use is_power_of_2()
https://git.kernel.org/mtd/c/04fc298c7d08
Best regards,
--
Tudor Ambarus <tudor.ambarus@microchip.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: spi-nor: use is_power_of_2()
@ 2021-03-08 6:20 ` Tudor Ambarus
0 siblings, 0 replies; 6+ messages in thread
From: Tudor Ambarus @ 2021-03-08 6:20 UTC (permalink / raw)
To: linux-kernel, linux-mtd, Michael Walle
Cc: Tudor Ambarus, Richard Weinberger, Miquel Raynal, Vignesh Raghavendra
On Sat, 6 Mar 2021 00:45:52 +0100, Michael Walle wrote:
> There is already a function to check if an integer is a power of 2. Use
> it.
Applied to spi-nor/next, thanks!
[1/1] mtd: spi-nor: use is_power_of_2()
https://git.kernel.org/mtd/c/04fc298c7d08
Best regards,
--
Tudor Ambarus <tudor.ambarus@microchip.com>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: spi-nor: use is_power_of_2()
2021-03-05 23:45 ` Michael Walle
@ 2021-03-08 9:01 ` Pratyush Yadav
-1 siblings, 0 replies; 6+ messages in thread
From: Pratyush Yadav @ 2021-03-08 9:01 UTC (permalink / raw)
To: Michael Walle
Cc: linux-mtd, linux-kernel, Tudor Ambarus, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
On 06/03/21 12:45AM, Michael Walle wrote:
> There is already a function to check if an integer is a power of 2. Use
> it.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
> drivers/mtd/spi-nor/core.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 0522304f52fa..4a315cb1c4db 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2336,11 +2336,8 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
> * If page_size is a power of two, the offset can be quickly
> * calculated with an AND operation. On the other cases we
> * need to do a modulus operation (more expensive).
> - * Power of two numbers have only one bit set and we can use
> - * the instruction hweight32 to detect if we need to do a
> - * modulus (do_div()) or not.
> */
> - if (hweight32(nor->page_size) == 1) {
> + if (is_power_of_2(nor->page_size)) {
> page_offset = addr & (nor->page_size - 1);
> } else {
> uint64_t aux = addr;
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
--
Regards,
Pratyush Yadav
Texas Instruments Inc.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: spi-nor: use is_power_of_2()
@ 2021-03-08 9:01 ` Pratyush Yadav
0 siblings, 0 replies; 6+ messages in thread
From: Pratyush Yadav @ 2021-03-08 9:01 UTC (permalink / raw)
To: Michael Walle
Cc: linux-mtd, linux-kernel, Tudor Ambarus, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
On 06/03/21 12:45AM, Michael Walle wrote:
> There is already a function to check if an integer is a power of 2. Use
> it.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
> drivers/mtd/spi-nor/core.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 0522304f52fa..4a315cb1c4db 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2336,11 +2336,8 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
> * If page_size is a power of two, the offset can be quickly
> * calculated with an AND operation. On the other cases we
> * need to do a modulus operation (more expensive).
> - * Power of two numbers have only one bit set and we can use
> - * the instruction hweight32 to detect if we need to do a
> - * modulus (do_div()) or not.
> */
> - if (hweight32(nor->page_size) == 1) {
> + if (is_power_of_2(nor->page_size)) {
> page_offset = addr & (nor->page_size - 1);
> } else {
> uint64_t aux = addr;
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
--
Regards,
Pratyush Yadav
Texas Instruments Inc.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-08 9:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 23:45 [PATCH] mtd: spi-nor: use is_power_of_2() Michael Walle
2021-03-05 23:45 ` Michael Walle
2021-03-08 6:20 ` Tudor Ambarus
2021-03-08 6:20 ` Tudor Ambarus
2021-03-08 9:01 ` Pratyush Yadav
2021-03-08 9:01 ` Pratyush Yadav
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.