hw: Replace some impossible checks by assertions
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
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
@@ -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
Laurent Vivier
AppliedRe: [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 byqdev_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.Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/gpio/max7310.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)hw/gpio/max7310.c +0
-2@@ -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
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
@@ -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
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_PINSdefinition.Suggested-by Cédric Le Goater <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
--- hw/ppc/ppc4xx_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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;
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
Laurent Vivier
AppliedRe: [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_PINSdefinition.Suggested-by Cédric Le Goater <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/ppc/ppc4xx_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/ppc4xx_pci.c +0
-0
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
Quoted 7 lines · Philippe Mathieu-Daudé
Trivial patches removing unreachable code.
Since v1:
- dropped patches queued
- replace dead code by assert (Peter)
- usePCI_NUM_PINSdefinition (Cédric)
Quoted 8 lines
Philippe Mathieu-Daudé (2):
hw/gpio/max7310: Remove impossible check hw/ppc/ppc4xx_pci: Replace magic value by thePCI_NUM_PINSdefinitionhw/gpio/max7310.c | 5 +---- hw/ppc/ppc4xx_pci.c | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-)
r~