Skip to contentSkip to conversation

hw: Replace some impossible checks by assertions

PATCH Applied Philippe Mathieu-Daudé 4 participants 7 messages Sep 10, 2020 – Sep 16, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover hw: Replace some impossible checks by assertions

Trivial patches removing unreachable code.

Since v1:
- dropped patches queued
- replace dead code by assert (Peter)
- use PCI_NUM_PINS definition (Cédric)

Philippe Mathieu-Daudé (2):
hw/gpio/max7310: Remove impossible check hw/ppc/ppc4xx_pci: Replace magic value by the PCI_NUM_PINS definition

 hw/gpio/max7310.c   | 5 +----
 hw/ppc/ppc4xx_pci.c | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/2 hw/gpio/max7310: Remove impossible check

The max7310_gpio_set() handler is static and only used by qdev_init_gpio_in, initialized with 8 IRQs. The 'line' argument can not be out of the [0-8[ range. Replace the dead code by an assertion.

---
 hw/gpio/max7310.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/gpio/max7310.c +1 -4
index 4f78774dc8f..158b0a074e5 100644
@@ -8,9 +8,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/hw.h"
 #include "hw/i2c/i2c.h"
-#include "hw/hw.h"
 #include "hw/irq.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
@@ -173,8 +171,7 @@ static const VMStateDescription vmstate_max7310 = {
 static void max7310_gpio_set(void *opaque, int line, int level)
 {
     MAX7310State *s = (MAX7310State *) opaque;
-    if (line >= ARRAY_SIZE(s->handler) || line  < 0)
-        hw_error("bad GPIO line");
+    assert(line >= 0 && line < ARRAY_SIZE(s->handler));
 
     if (level)
         s->level |= s->direction & (1 << line);
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH v2 1/2] hw/gpio/max7310: Remove impossible check

Le 10/09/2020 à 09:23, Philippe Mathieu-Daudé a écrit :

Quoted 27 lines

The max7310_gpio_set() handler is static and only used by qdev_init_gpio_in, initialized with 8 IRQs. The 'line' argument can not be out of the [0-8[ range. Replace the dead code by an assertion.

---
 hw/gpio/max7310.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/gpio/max7310.c +0 -2
index 4f78774dc8f..158b0a074e5 100644
@@ -8,9 +8,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/hw.h"
 #include "hw/i2c/i2c.h"
-#include "hw/hw.h"
 #include "hw/irq.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"

hw/gpio/max7310.c static const VMStateDescription vmstate_max7310 = { · line 177

Quoted 9 lines
hw/gpio/max7310.c +1 -2
@@ -173,8 +171,7 @@ static const VMStateDescription vmstate_max7310 = {
 static void max7310_gpio_set(void *opaque, int line, int level)
 {
     MAX7310State *s = (MAX7310State *) opaque;
-    if (line >= ARRAY_SIZE(s->handler) || line  < 0)
-        hw_error("bad GPIO line");
+    assert(line >= 0 && line < ARRAY_SIZE(s->handler));
 
     if (level)
         s->level |= s->direction & (1 << line);

Applied to my trivial-patches branch.

Thanks,
Laurent

#3 lore raw

PATCH v2 2/2 hw/ppc/ppc4xx_pci: Replace magic value by the PCI_NUM_PINS definition

In reply to Philippe Mathieu-Daudé

Replace the magic '4' value by the PCI_NUM_PINS definition.

---
 hw/ppc/ppc4xx_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/ppc4xx_pci.c +1 -1
index 503ef46b39a..930be78361d 100644
@@ -54,7 +54,7 @@ struct PPC4xxPCIState {
 
     struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];
     struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];
-    qemu_irq irq[4];
+    qemu_irq irq[PCI_NUM_PINS];
 
     MemoryRegion container;
     MemoryRegion iomem;
Signature · 1 line
2.26.2
Acked-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] hw/ppc/ppc4xx_pci: Replace magic value by the PCI_NUM_PINS definition

Quoted 4 lines · Philippe Mathieu-Daudé

Replace the magic '4' value by the PCI_NUM_PINS definition.

Quoted 17 lines
---
 hw/ppc/ppc4xx_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/ppc4xx_pci.c +1 -1
index 503ef46b39a..930be78361d 100644
@@ -54,7 +54,7 @@ struct PPC4xxPCIState {
 
     struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];
     struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];
-    qemu_irq irq[4];
+    qemu_irq irq[PCI_NUM_PINS];
 
     MemoryRegion container;
     MemoryRegion iomem;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw

Re: [PATCH v2 2/2] hw/ppc/ppc4xx_pci: Replace magic value by the PCI_NUM_PINS definition

In reply to Philippe Mathieu-Daudé

Le 10/09/2020 à 09:23, Philippe Mathieu-Daudé a écrit :

Quoted 14 lines

Replace the magic '4' value by the PCI_NUM_PINS definition.

---
 hw/ppc/ppc4xx_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/ppc4xx_pci.c +0 -0
index 503ef46b39a..930be78361d 100644

hw/ppc/ppc4xx_pci.c struct PPC4xxPCIState { · line 60

Quoted 8 lines
hw/ppc/ppc4xx_pci.c +1 -1
@@ -54,7 +54,7 @@ struct PPC4xxPCIState {
 
     struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];
     struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];
-    qemu_irq irq[4];
+    qemu_irq irq[PCI_NUM_PINS];
 
     MemoryRegion container;
     MemoryRegion iomem;

Applied to my trivial-patches branch.

Thanks,
Laurent

Reviewed-by on the v2 series
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Trivial patches removing unreachable code.

Since v1:
- dropped patches queued
- replace dead code by assert (Peter)
- use PCI_NUM_PINS definition (Cédric)

Quoted 8 lines

Philippe Mathieu-Daudé (2):
hw/gpio/max7310: Remove impossible check hw/ppc/ppc4xx_pci: Replace magic value by the PCI_NUM_PINS definition

 hw/gpio/max7310.c   | 5 +----
 hw/ppc/ppc4xx_pci.c | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

r~