On 5 April 2012 16:48, Igor Mitsyanko <i.mitsya...@samsung.com> wrote:
> @@ -536,8 +541,8 @@ static void sd_function_switch(SDState *sd, uint32_t arg)
>
>  static inline int sd_wp_addr(SDState *sd, uint32_t addr)
>  {
> -    return sd->wp_groups[addr >>
> -            (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)];
> +    return test_bit(addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT),
> +            sd->wp_groups);

Looking at how often the expression "addr >> (HWBLOCK_SHIFT +
SECTOR_SHIFT + WPGROUP_SHIFT)"
turns up in this file, I suspect that it would be helpful to have
a function
static uint32_t addr_to_wpnum(uint64_t addr) {
    return addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT);
}

But that should be in a separate patch, and it's optional.

>  }
>
>  static void sd_lock_command(SDState *sd)
> @@ -560,8 +565,8 @@ static void sd_lock_command(SDState *sd)
>             sd->card_status |= LOCK_UNLOCK_FAILED;
>             return;
>         }
> -        memset(sd->wp_groups, 0, sizeof(int) * (sd->size >>
> -                        (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)));
> +        bitmap_zero(sd->wp_groups, BITS_TO_LONGS((sd->size >> (HWBLOCK_SHIFT 
> +
> +                SECTOR_SHIFT + WPGROUP_SHIFT)) + 1));

This is wrong -- bitmap_zero() takes a bit count, so you don't need
to do BITS_TO_LONGS. Also where has the + 1 come from?

Otherwise looks good.

-- PMM

Reply via email to