Skip to contentSkip to conversation

ati-vga Coverity fixes

PATCH Applied BALATON Zoltan 3 participants 11 messages Mar 30 – Mar 31

lore
Share & tools
lore
#0 lore raw

cover ati-vga Coverity fixes

Small patches to address Coverity warnings.

BALATON Zoltan (2):
ati-vga: Silence warning about operator precedence
ati-vga: Add upper limit to x-linear-aper-size property

 hw/display/ati.c    | 4 ++++
 hw/display/ati_2d.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.41.3
#1 lore raw

PATCH 1/2 ati-vga: Silence warning about operator precedence

Coverity in CID 1645969 warns about possible operator precendence issue which is a false positive in this case but simplify the expression to silence the warning.

---
 hw/display/ati_2d.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/ati_2d.c +1 -1
index 23527b2c50..9baf6ff37b 100644
@@ -91,7 +91,7 @@ static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DCtx *ctx)
     ctx->host_data_active = s->host_data.active;
     ctx->left_to_right = s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT;
     ctx->top_to_bottom = s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM;
-    ctx->need_swap = HOST_BIG_ENDIAN != s->vga.big_endian_fb ? true : false;
+    ctx->need_swap = (HOST_BIG_ENDIAN != s->vga.big_endian_fb);
     ctx->frgd_clr = s->regs.dp_brush_frgd_clr;
     ctx->palette = s->vga.palette;
     ctx->dst_offset = s->regs.dst_offset;
Signature · 1 line
2.41.3
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ati-vga: Silence warning about operator precedence

Quoted 15 lines · BALATON Zoltan

Coverity in CID 1645969 warns about possible operator precendence issue which is a false positive in this case but simplify the expression to silence the warning.

---
 hw/display/ati_2d.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/ati_2d.c +0 -0
index 23527b2c50..9baf6ff37b 100644

hw/display/ati_2d.c static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DCtx *ctx)

Quoted 9 lines
hw/display/ati_2d.c +1 -2
@@ -91,7 +91,7 @@ static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DCtx *ctx)
     ctx->host_data_active = s->host_data.active;
     ctx->left_to_right = s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT;
     ctx->top_to_bottom = s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM;
-    ctx->need_swap = HOST_BIG_ENDIAN != s->vga.big_endian_fb ? true : false;
+    ctx->need_swap = (HOST_BIG_ENDIAN != s->vga.big_endian_fb);
     ctx->frgd_clr = s->regs.dp_brush_frgd_clr;
     ctx->palette = s->vga.palette;
     ctx->dst_offset = s->regs.dst_offset;
--

thanks
-- PMM

#3 lore raw

Re: [PATCH 1/2] ati-vga: Silence warning about operator precedence

In reply to BALATON Zoltan
Quoted 14 lines · BALATON Zoltan

Coverity in CID 1645969 warns about possible operator precendence issue which is a false positive in this case but simplify the expression to silence the warning.

---
  hw/display/ati_2d.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/ati_2d.c +0 -0
index 23527b2c50..9baf6ff37b 100644

hw/display/ati_2d.c static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DCtx *ctx) · line 94

Quoted 5 lines
hw/display/ati_2d.c +1 -1
@@ -91,7 +91,7 @@ static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DCtx *ctx)
      ctx->host_data_active = s->host_data.active;
      ctx->left_to_right = s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT;
      ctx->top_to_bottom = s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM;
-    ctx->need_swap = HOST_BIG_ENDIAN != s->vga.big_endian_fb ? true : false;
+    ctx->need_swap = (HOST_BIG_ENDIAN != s->vga.big_endian_fb);

Do we really need the parenthesis?

Quoted 3 lines
hw/display/ati_2d.c +0 -0
      ctx->frgd_clr = s->regs.dp_brush_frgd_clr;
      ctx->palette = s->vga.palette;
      ctx->dst_offset = s->regs.dst_offset;
#4 lore raw

Re: [PATCH 1/2] ati-vga: Silence warning about operator precedence

Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · BALATON Zoltan

Coverity in CID 1645969 warns about possible operator precendence issue which is a false positive in this case but simplify the expression to silence the warning.

---
  hw/display/ati_2d.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

hw/display/ati_2d.c static void setup_2d_blt_ctx(const ATIVGAState *s, · line 96

Quoted 12 lines
hw/display/ati_2d.c +1 -1
index 23527b2c50..9baf6ff37b 100644
@@ -91,7 +91,7 @@ static void setup_2d_blt_ctx(const ATIVGAState *s, 
 ATI2DCtx *ctx)
      ctx->host_data_active = s->host_data.active;
      ctx->left_to_right = s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT;
      ctx->top_to_bottom = s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM;
-    ctx->need_swap = HOST_BIG_ENDIAN != s->vga.big_endian_fb ? true : 
 false;
+    ctx->need_swap = (HOST_BIG_ENDIAN != s->vga.big_endian_fb);

Do we really need the parenthesis?

Should not be needed but it may be more readable and Coverity warned about the original that did not need parenthesis either so it seems the safest to write it this way.

Regards,
BALATON Zoltan

Quoted 5 lines
Quoted 3 lines
hw/display/ati_2d.c +0 -0
      ctx->frgd_clr = s->regs.dp_brush_frgd_clr;
      ctx->palette = s->vga.palette;
      ctx->dst_offset = s->regs.dst_offset;
#5 lore raw

PATCH 2/2 ati-vga: Add upper limit to x-linear-aper-size property

In reply to BALATON Zoltan

Coverity warns in CID 1645968 about possible integer overflow. This should never happen but to ensure that, add an upper limit on the x-linear-aper-size. This may not silence the warning but makes sure users cannot cause an overflow.

---
 hw/display/ati.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/display/ati.c +4 -0
index fc19737d1f..97d871b1e2 100644
@@ -1130,6 +1130,10 @@ static void ati_vga_realize(PCIDevice *dev, Error **errp)
             s->linear_aper_sz = ATI_R100_LINEAR_APER_SIZE;
         }
     }
+    if (s->linear_aper_sz > 256 * MiB) {
+        error_setg(errp, "x-linear-aper-size is too large (maximum 256 MiB)");
+        return;
+    }
     if (s->linear_aper_sz < 16 * MiB) {
         error_setg(errp, "x-linear-aper-size is too small (minimum 16 MiB)");
         return;
Signature · 1 line
2.41.3
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] ati-vga: Add upper limit to x-linear-aper-size property

Quoted 27 lines · BALATON Zoltan

Coverity warns in CID 1645968 about possible integer overflow. This should never happen but to ensure that, add an upper limit on the x-linear-aper-size. This may not silence the warning but makes sure users cannot cause an overflow.

---
 hw/display/ati.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/display/ati.c +4 -1
index fc19737d1f..97d871b1e2 100644
@@ -1130,6 +1130,10 @@ static void ati_vga_realize(PCIDevice *dev, Error **errp)
             s->linear_aper_sz = ATI_R100_LINEAR_APER_SIZE;
         }
     }
+    if (s->linear_aper_sz > 256 * MiB) {
+        error_setg(errp, "x-linear-aper-size is too large (maximum 256 MiB)");
+        return;
+    }
     if (s->linear_aper_sz < 16 * MiB) {
         error_setg(errp, "x-linear-aper-size is too small (minimum 16 MiB)");
         return;
--
Quoted 2 lines

2.41.3

thanks
-- PMM

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] ati-vga: Add upper limit to x-linear-aper-size property

In reply to BALATON Zoltan
Quoted 9 lines · BALATON Zoltan

Coverity warns in CID 1645968 about possible integer overflow. This should never happen but to ensure that, add an upper limit on the x-linear-aper-size. This may not silence the warning but makes sure users cannot cause an overflow.

---
  hw/display/ati.c | 4 ++++
  1 file changed, 4 insertions(+)
#8 lore raw
In reply to BALATON Zoltan
Quoted 5 lines · BALATON Zoltan

Small patches to address Coverity warnings.

BALATON Zoltan (2):
ati-vga: Silence warning about operator precedence
ati-vga: Add upper limit to x-linear-aper-size property

Queued via hw-misc tree, thanks.

#9 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · BALATON Zoltan

Small patches to address Coverity warnings.

BALATON Zoltan (2):
ati-vga: Silence warning about operator precedence
ati-vga: Add upper limit to x-linear-aper-size property

Queued via hw-misc tree, thanks.

Thanks. Could somebody review the cirrus-vga patch too so it could be picked up?

Regards,
BALATON Zoltan

#10 lore raw
Quoted 11 lines · BALATON Zoltan
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · BALATON Zoltan

Small patches to address Coverity warnings.

BALATON Zoltan (2):
   ati-vga: Silence warning about operator precedence
   ati-vga: Add upper limit to x-linear-aper-size property

Queued via hw-misc tree, thanks.

Thanks. Could somebody review the cirrus-vga patch too so it could be picked up?

I skipped them because Gerd left a comment.