diff mbox series

[29/49] memstick: replace bitmap_weight with bitmap_weight_eq where appropriate

Message ID 20220210224933.379149-30-yury.norov@gmail.com (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Yury Norov Feb. 10, 2022, 10:49 p.m. UTC
msb_validate_used_block_bitmap() calls bitmap_weight() to compare the
weight of bitmap with a given number. We can do it more efficiently with
bitmap_weight_eq because conditional bitmap_weight may stop traversing the
bitmap earlier, as soon as condition is (or can't be) met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Shubhankar Kuranagatti <shubhankar.vk@gmail.com>
---
 drivers/memstick/core/ms_block.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ulf Hansson Feb. 17, 2022, 3:39 p.m. UTC | #1
On Fri, 11 Feb 2022 at 00:55, Yury Norov <yury.norov@gmail.com> wrote:
>
> msb_validate_used_block_bitmap() calls bitmap_weight() to compare the
> weight of bitmap with a given number. We can do it more efficiently with
> bitmap_weight_eq because conditional bitmap_weight may stop traversing the
> bitmap earlier, as soon as condition is (or can't be) met.
>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> Acked-by: Shubhankar Kuranagatti <shubhankar.vk@gmail.com>

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/memstick/core/ms_block.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
> index 0cda6c6baefc..5cdd987e78f7 100644
> --- a/drivers/memstick/core/ms_block.c
> +++ b/drivers/memstick/core/ms_block.c
> @@ -155,8 +155,8 @@ static int msb_validate_used_block_bitmap(struct msb_data *msb)
>         for (i = 0; i < msb->zone_count; i++)
>                 total_free_blocks += msb->free_block_count[i];
>
> -       if (msb->block_count - bitmap_weight(msb->used_blocks_bitmap,
> -                                       msb->block_count) == total_free_blocks)
> +       if (bitmap_weight_eq(msb->used_blocks_bitmap, msb->block_count,
> +                               msb->block_count - total_free_blocks))
>                 return 0;
>
>         pr_err("BUG: free block counts don't match the bitmap");
> --
> 2.32.0
>
Yury Norov Feb. 17, 2022, 4:55 p.m. UTC | #2
On Thu, Feb 17, 2022 at 7:39 AM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Fri, 11 Feb 2022 at 00:55, Yury Norov <yury.norov@gmail.com> wrote:
> >
> > msb_validate_used_block_bitmap() calls bitmap_weight() to compare the
> > weight of bitmap with a given number. We can do it more efficiently with
> > bitmap_weight_eq because conditional bitmap_weight may stop traversing the
> > bitmap earlier, as soon as condition is (or can't be) met.
> >
> > Signed-off-by: Yury Norov <yury.norov@gmail.com>
> > Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> > Acked-by: Shubhankar Kuranagatti <shubhankar.vk@gmail.com>
>
> Applied for next, thanks!

Hi Ulf,

This patch depends on patch 26/49 "bitmap: add bitmap_weight_{cmp, eq,
gt, ge, lt, le} functions"
from this series. Can you  make sure you applied them together? Or I can
apply it later.

Thanks,
Yury
Ulf Hansson Feb. 22, 2022, 3:49 p.m. UTC | #3
On Thu, 17 Feb 2022 at 17:55, Yury Norov <yury.norov@gmail.com> wrote:
>
> On Thu, Feb 17, 2022 at 7:39 AM Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > On Fri, 11 Feb 2022 at 00:55, Yury Norov <yury.norov@gmail.com> wrote:
> > >
> > > msb_validate_used_block_bitmap() calls bitmap_weight() to compare the
> > > weight of bitmap with a given number. We can do it more efficiently with
> > > bitmap_weight_eq because conditional bitmap_weight may stop traversing the
> > > bitmap earlier, as soon as condition is (or can't be) met.
> > >
> > > Signed-off-by: Yury Norov <yury.norov@gmail.com>
> > > Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> > > Acked-by: Shubhankar Kuranagatti <shubhankar.vk@gmail.com>
> >
> > Applied for next, thanks!
>
> Hi Ulf,
>
> This patch depends on patch 26/49 "bitmap: add bitmap_weight_{cmp, eq,
> gt, ge, lt, le} functions"
> from this series. Can you  make sure you applied them together? Or I can
> apply it later.

I can't apply them, unless there is an immutable branch being shared
between the different trees.

Therefore I have dropped the patch for now.

Kind regards
Uffe
diff mbox series

Patch

diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index 0cda6c6baefc..5cdd987e78f7 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -155,8 +155,8 @@  static int msb_validate_used_block_bitmap(struct msb_data *msb)
 	for (i = 0; i < msb->zone_count; i++)
 		total_free_blocks += msb->free_block_count[i];
 
-	if (msb->block_count - bitmap_weight(msb->used_blocks_bitmap,
-					msb->block_count) == total_free_blocks)
+	if (bitmap_weight_eq(msb->used_blocks_bitmap, msb->block_count,
+				msb->block_count - total_free_blocks))
 		return 0;
 
 	pr_err("BUG: free block counts don't match the bitmap");