Patchwork [V2,04/10] hw/sd.c: make sd_wp_addr() return bool

login
register
mail settings
Submitter Mitsyanko Igor
Date April 5, 2012, 3:48 p.m.
Message ID <1333640913-16028-5-git-send-email-i.mitsyanko@samsung.com>
Download mbox | patch
Permalink /patch/151062/
State New
Headers show

Comments

Mitsyanko Igor - April 5, 2012, 3:48 p.m.
For the sake of code clarity

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
---
 hw/sd.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Peter Maydell - April 11, 2012, 9:59 a.m.
On 5 April 2012 16:48, Igor Mitsyanko <i.mitsyanko@samsung.com> wrote:
> For the sake of code clarity
>
> Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
> ---
>  hw/sd.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/sd.c b/hw/sd.c
> index e1c998c..7160e8c 100644
> --- a/hw/sd.c
> +++ b/hw/sd.c
> @@ -539,9 +539,9 @@ static void sd_function_switch(SDState *sd, uint32_t arg)
>     sd->data[66] = crc & 0xff;
>  }
>
> -static inline int sd_wp_addr(SDState *sd, uint32_t addr)
> +static inline bool sd_wp_addr(SDState *sd, uint32_t addr)
>  {
> -    return test_bit(addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT),
> +    return !!test_bit(addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT),
>             sd->wp_groups);
>  }

The !! is unnecessary: (a) test_bit always returns 0 or 1 and (b)
the cast from int to bool will convert anything-not-zero to 1 anyway.

-- PMM

Patch

diff --git a/hw/sd.c b/hw/sd.c
index e1c998c..7160e8c 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -539,9 +539,9 @@  static void sd_function_switch(SDState *sd, uint32_t arg)
     sd->data[66] = crc & 0xff;
 }
 
-static inline int sd_wp_addr(SDState *sd, uint32_t addr)
+static inline bool sd_wp_addr(SDState *sd, uint32_t addr)
 {
-    return test_bit(addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT),
+    return !!test_bit(addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT),
             sd->wp_groups);
 }