Skip to contentSkip to conversation

hw/xics: Fix one-bit signed bitfields

PATCH In review Stefan Weil 2 participants 3 messages Sep 4, 2012 – Sep 22, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/xics: Fix one-bit signed bitfields

Report from smatch:

xics.c:169:19: error: dubious one-bit signed bitfield xics.c:170:15: error: dubious one-bit signed bitfield xics.c:171:19: error: dubious one-bit signed bitfield xics.c:172:25: error: dubious one-bit signed bitfield

Instead of replacing 'int' by 'unsigned', 'bool' was used because all 4 values are boolean values.

Replacing 0 and 1 in the assignments by false and true looks better for those boolean values.

---
 hw/xics.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
hw/xics.c +11 -11
index b674771..8a2f70f 100644
@@ -166,10 +166,10 @@ struct ics_irq_state {
     uint8_t priority;
     uint8_t saved_priority;
     enum xics_irq_type type;
-    int asserted:1;
-    int sent:1;
-    int rejected:1;
-    int masked_pending:1;
+    bool asserted:1;
+    bool sent:1;
+    bool rejected:1;
+    bool masked_pending:1;
 };
 
 struct ics_state {
@@ -192,7 +192,7 @@ static void resend_msi(struct ics_state *ics, int srcno)
 
     /* FIXME: filter by server#? */
     if (irq->rejected) {
-        irq->rejected = 0;
+        irq->rejected = false;
         if (irq->priority != 0xff) {
             icp_irq(ics->icp, irq->server, srcno + ics->offset,
                     irq->priority);
@@ -205,7 +205,7 @@ static void resend_lsi(struct ics_state *ics, int srcno)
     struct ics_irq_state *irq = ics->irqs + srcno;
 
     if ((irq->priority != 0xff) && irq->asserted && !irq->sent) {
-        irq->sent = 1;
+        irq->sent = true;
         icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority);
     }
 }
@@ -216,7 +216,7 @@ static void set_irq_msi(struct ics_state *ics, int srcno, int val)
 
     if (val) {
         if (irq->priority == 0xff) {
-            irq->masked_pending = 1;
+            irq->masked_pending = true;
             /* masked pending */ ;
         } else  {
             icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority);
@@ -252,7 +252,7 @@ static void write_xive_msi(struct ics_state *ics, int srcno)
         return;
     }
 
-    irq->masked_pending = 0;
+    irq->masked_pending = false;
     icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority);
 }
 
@@ -281,8 +281,8 @@ static void ics_reject(struct ics_state *ics, int nr)
 {
     struct ics_irq_state *irq = ics->irqs + nr - ics->offset;
 
-    irq->rejected = 1; /* Irrelevant but harmless for LSI */
-    irq->sent = 0; /* Irrelevant but harmless for MSI */
+    irq->rejected = true; /* Irrelevant but harmless for LSI */
+    irq->sent = false; /* Irrelevant but harmless for MSI */
 }
 
 static void ics_resend(struct ics_state *ics)
@@ -307,7 +307,7 @@ static void ics_eoi(struct ics_state *ics, int nr)
     struct ics_irq_state *irq = ics->irqs + srcno;
 
     if (irq->type == XICS_LSI) {
-        irq->sent = 0;
+        irq->sent = false;
     }
 }
 
Signature · 1 line
1.7.10
#1 lore raw
Quoted 7 lines · Stefan Weil

Report from smatch:

xics.c:169:19: error: dubious one-bit signed bitfield xics.c:170:15: error: dubious one-bit signed bitfield xics.c:171:19: error: dubious one-bit signed bitfield xics.c:172:25: error: dubious one-bit signed bitfield

Quoted 5 lines

Instead of replacing 'int' by 'unsigned', 'bool' was used because all 4 values are boolean values.

Replacing 0 and 1 in the assignments by false and true looks better for those boolean values.

If we're changing this we should just drop the bitfield usage entirely and use plain bool, I think.

-- PMM

#2 lore raw

Am 04.09.2012 22:53, schrieb Peter Maydell:

Quoted 11 lines · Stefan Weil
Quoted 10 lines

Report from smatch:

xics.c:169:19: error: dubious one-bit signed bitfield xics.c:170:15: error: dubious one-bit signed bitfield xics.c:171:19: error: dubious one-bit signed bitfield xics.c:172:25: error: dubious one-bit signed bitfield

Instead of replacing 'int' by 'unsigned', 'bool' was used because all 4 values are boolean values.

Quoted 7 lines
Quoted 2 lines

Replacing 0 and 1 in the assignments by false and true looks better for those boolean values.

If we're changing this we should just drop the bitfield usage entirely and use plain bool, I think.

-- PMM

David, could you please review the patch and Peter's suggestion? See also http://patchwork.ozlabs.org/patch/181671/

Thanks,

Stefan Weil