Fix up sam460ex fixes
cover Fix up sam460ex fixes
Accidentally the wrong version of this series was committed, this series fixes that up to the last version that was meant to be merged.
BALATON Zoltan (3):
Revert "sam460ex: Remove FDT_PPC dependency from KConfig" Revert "ppc4xx: Move common dependency on serial to common option"
sam460ex: Use type cast macro instead of simple cast
hw/ppc/Kconfig | 6 +++++- hw/ppc/sam460ex.c | 7 ++----- 2 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.21.3
PATCH 2/3 Revert "ppc4xx: Move common dependency on serial to common option"
This reverts commit e6d5106786 which was added mistakenly. While this change works it was suggested during review that keeping dependencies explicit for each board may be better than listing them in a common option so keep the previous version and revert this change.
--- hw/ppc/Kconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/ppc/Kconfig +4 -1
@@ -36,6 +36,7 @@ config PPC405 select M48T59 select PFLASH_CFI02 select PPC4XX + select SERIAL config PPC440 bool
@@ -44,6 +45,7 @@ config PPC440 imply E1000_PCI select PCI_EXPRESS select PPC4XX + select SERIAL select FDT_PPC config PPC4XX
@@ -51,7 +53,6 @@ config PPC4XX select BITBANG_I2C select PCI select PPC_UIC - select SERIAL config SAM460EX bool
@@ -60,6 +61,7 @@ config SAM460EX select IDE_SII3112 select M41T80 select PPC440 + select SERIAL select SM501 select SMBUS_EEPROM select USB_EHCI_SYSBUS
@@ -121,6 +123,7 @@ config VIRTEX bool select PPC4XX select PFLASH_CFI01 + select SERIAL select XILINX select XILINX_ETHLITE select FDT_PPC
Signature · 1 line
2.21.3
PATCH 3/3 sam460ex: Use type cast macro instead of simple cast
In reply to BALATON Zoltan viaUse the PCI_BUS type cast macro to convert result of qdev_get_child_bus(). Also remove the check for NULL afterwards which should not be needed because sysbus_create_simple() uses error_abort and PCI_BUS macro also checks its argument by default so this shouldn't fail here.
--- hw/ppc/sam460ex.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/ppc/sam460ex.c +2 -5
@@ -384,11 +384,8 @@ static void sam460ex_init(MachineState *machine)ppc460ex_pcie_init (env);/* All PCI irqs are connected to the same UIC pin (cf. UBoot source) */ dev =sysbus_create_simple ("ppc440-pcix-host" ,0xc0ec00000 , uic[1 ][0 ]); - pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci.0" ); -if (!pci_bus) { -error_report ("couldn't create PCI controller!" ); -exit (1 ); - } + pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); +memory_region_init_alias (isa,NULL ,"isa_mmio" ,get_system_io (),0 ,0x10000 );memory_region_add_subregion (get_system_memory (),0xc08000000 , isa);
Signature · 1 line
2.21.3
PATCH 1/3 Revert "sam460ex: Remove FDT_PPC dependency from KConfig"
In reply to BALATON Zoltan viaThis reverts commit 038da2adf that was mistakenly added, this dependency is still needed to get libfdt dependencies even if fdt.o is not needed by sam460ex.
--- hw/ppc/Kconfig | 1 + 1 file changed, 1 insertion(+)
hw/ppc/Kconfig +1 -0
@@ -64,6 +64,7 @@ config SAM460EX select SMBUS_EEPROM select USB_EHCI_SYSBUS select USB_OHCI + select FDT_PPC config PREP bool
Signature · 1 line
2.21.3
Re: [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast
In reply to BALATON Zoltan viaQuoted 3 lines · On Wed, 6 Jan 2021 16:24:01 +0100 BALATON Zoltan via <[email protected]>…
Use the
PCI_BUStype cast macro to convert result ofqdev_get_child_bus(). Also remove the check for NULL afterwards which should not be needed becausesysbus_create_simple()useserror_abort
It seems to me that sysbus_create_simple() doesn't return NULL because it ends up calling object_new_with_type(). This allocates the object with either g_malloc() or qemu_memalign(), both of which abort on failure.
Quoted 1 line
and
PCI_BUSmacro also checks its argument by default so this
AFAICT, PCI_BUS() and all other instance type checking macros are happy with a NULL argument. They simply return NULL in this case.
Quoted 12 lines
shouldn't fail here.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/sam460ex.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/ppc/sam460ex.c +0
-0
hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 388
Quoted 10 lines
hw/ppc/sam460ex.c +2
-5@@ -384,11 +384,8 @@ static void sam460ex_init(MachineState *machine)ppc460ex_pcie_init (env);/* All PCI irqs are connected to the same UIC pin (cf. UBoot source) */ dev =sysbus_create_simple ("ppc440-pcix-host" ,0xc0ec00000 , uic[1 ][0 ]); - pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci.0" ); -if (!pci_bus) { -error_report ("couldn't create PCI controller!" ); -exit (1 ); - } + pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); +
But PCI_BUS() is being passed qdev_get_child_bus(dev, "pci.0"), not dev... so the real question here is whether this can return NULL or not. And if this happens, is this a (1) user or (2) programming error ?
If (1) then the "if (!pci_bus) { }" should be kept. If (2) then it should be converted to an assert().
Quoted 3 lines
hw/ppc/sam460ex.c +0
-0memory_region_init_alias (isa,NULL ,"isa_mmio" ,get_system_io (),0 ,0x10000 );memory_region_add_subregion (get_system_memory (),0xc08000000 , isa);
Re: [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast
Quoted 12 lines · Greg Kurz
Quoted 3 lines · On Wed, 6 Jan 2021 16:24:01 +0100 BALATON Zoltan via <[email protected]>…
Use the
PCI_BUStype cast macro to convert result ofqdev_get_child_bus(). Also remove the check for NULL afterwards which should not be needed becausesysbus_create_simple()useserror_abortIt seems to me that
sysbus_create_simple()doesn't return NULL because it ends up callingobject_new_with_type(). This allocates the object with eitherg_malloc()orqemu_memalign(), both of which abort on failure.
Quoted 4 lines
Quoted 1 line
and
PCI_BUSmacro also checks its argument by default so thisAFAICT,
PCI_BUS()and all other instance type checking macros are happy with a NULL argument. They simply return NULL in this case.
This wasn't my experience when I've got an error in code and got a NULL pointer here (on pegasos2 board but same situation). At least with qom-debug enabled (which I think is on by default unless explicitly disabled in configure) this will abort if the object is not the right type.
Quoted 28 lines
Quoted 12 lines
shouldn't fail here.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/sam460ex.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/ppc/sam460ex.c +0
-0hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 388
Quoted 10 lines
hw/ppc/sam460ex.c +2
-5@@ -384,11 +384,8 @@ static void sam460ex_init(MachineState *machine)ppc460ex_pcie_init (env);/* All PCI irqs are connected to the same UIC pin (cf. UBoot source) */ dev =sysbus_create_simple ("ppc440-pcix-host" ,0xc0ec00000 , uic[1 ][0 ]); - pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci.0" ); -if (!pci_bus) { -error_report ("couldn't create PCI controller!" ); -exit (1 ); - } + pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); +But
PCI_BUS()is being passedqdev_get_child_bus(dev, "pci.0"), not dev... so the real question here is whether this can return NULL or not. And if this happens, is this a (1) user or (2) programming error ?
Quoted 2 lines
If (1) then the "if (!pci_bus) { }" should be kept. If (2) then it should be converted to an
assert().
I think it can only fail if the ppc440-pcix-host type is changed to not have a pci.0 child any more which is a programming error that's very unlikely to happen but if needed an assert could be added but I don't think that's really necessary. The error_report was definitely not needed as it's not a user error in any case.
Regards,
BALATON Zoltan
Quoted 5 lines
Quoted 3 lines
hw/ppc/sam460ex.c +0
-0memory_region_init_alias (isa,NULL ,"isa_mmio" ,get_system_io (),0 ,0x10000 );memory_region_add_subregion (get_system_memory (),0xc08000000 , isa);
Re: [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast
Quoted 15 lines · On Thu, 7 Jan 2021 10:45:26 +0100 BALATON Zoltan <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Quoted 3 lines · On Wed, 6 Jan 2021 16:24:01 +0100 BALATON Zoltan via <[email protected]>…
Use the
PCI_BUStype cast macro to convert result ofqdev_get_child_bus(). Also remove the check for NULL afterwards which should not be needed becausesysbus_create_simple()useserror_abortIt seems to me that
sysbus_create_simple()doesn't return NULL because it ends up callingobject_new_with_type(). This allocates the object with eitherg_malloc()orqemu_memalign(), both of which abort on failure.Quoted 1 line
and
PCI_BUSmacro also checks its argument by default so this
Quoted 9 lines
Quoted 2 lines
AFAICT,
PCI_BUS()and all other instance type checking macros are happy with a NULL argument. They simply return NULL in this case.This wasn't my experience when I've got an error in code and got a NULL pointer here (on pegasos2 board but same situation). At least with qom-debug enabled (which I think is on by default unless explicitly disabled in configure) this will abort if the object is not the right type.
You're right that qom-cast-debug is enabled by default and that it causes object_dynamic_cast_assert() to abort on type mismatch, but definitely not with a NULL value, as mentioned in this very old commit:
commit b7f43fe46029d8fd0594cd599fa2599dcce0f553
Author: Paolo Bonzini <[email protected]> Date: Fri Nov 23 16:56:17 2012 +0100
qom: dynamic_cast of NULL is always NULL
Trying to cast a NULL value will cause a crash. Returning NULL is also sensible, and it is also what the type-unsafe DO_UPCAST macro does.
Maybe this should be documented in the function header in "qom/object.h".
Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
shouldn't fail here.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/sam460ex.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/ppc/sam460ex.c +0
-0hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 388
Quoted 10 lines
hw/ppc/sam460ex.c +2
-5@@ -384,11 +384,8 @@ static void sam460ex_init(MachineState *machine)ppc460ex_pcie_init (env);/* All PCI irqs are connected to the same UIC pin (cf. UBoot source) */ dev =sysbus_create_simple ("ppc440-pcix-host" ,0xc0ec00000 , uic[1 ][0 ]); - pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci.0" ); -if (!pci_bus) { -error_report ("couldn't create PCI controller!" ); -exit (1 ); - } + pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); +But
PCI_BUS()is being passedqdev_get_child_bus(dev, "pci.0"), not dev... so the real question here is whether this can return NULL or not. And if this happens, is this a (1) user or (2) programming error ?
Quoted 9 lines
Quoted 2 lines
If (1) then the "if (!pci_bus) { }" should be kept. If (2) then it should be converted to an
assert().I think it can only fail if the ppc440-pcix-host type is changed to not have a pci.0 child any more which is a programming error that's very unlikely to happen but if needed an assert could be added but I don't think that's really necessary. The
error_reportwas definitely not needed as it's not a user error in any case.
I was also thinking about a programming error. Whether to add an assert() or not is up to you, you're the maintainer for this code :)
Quoted 8 lines
Regards,
BALATON ZoltanQuoted 5 lines
Quoted 3 lines
hw/ppc/sam460ex.c +0
-0memory_region_init_alias (isa,NULL ,"isa_mmio" ,get_system_io (),0 ,0x10000 );memory_region_add_subregion (get_system_memory (),0xc08000000 , isa);
Re: [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast
Quoted 28 lines · Greg Kurz
Quoted 15 lines · On Thu, 7 Jan 2021 10:45:26 +0100 BALATON Zoltan <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Quoted 3 lines · On Wed, 6 Jan 2021 16:24:01 +0100 BALATON Zoltan via <[email protected]>…
Use the
PCI_BUStype cast macro to convert result ofqdev_get_child_bus(). Also remove the check for NULL afterwards which should not be needed becausesysbus_create_simple()useserror_abortIt seems to me that
sysbus_create_simple()doesn't return NULL because it ends up callingobject_new_with_type(). This allocates the object with eitherg_malloc()orqemu_memalign(), both of which abort on failure.Quoted 1 line
and
PCI_BUSmacro also checks its argument by default so thisQuoted 9 lines
Quoted 2 lines
AFAICT,
PCI_BUS()and all other instance type checking macros are happy with a NULL argument. They simply return NULL in this case.This wasn't my experience when I've got an error in code and got a NULL pointer here (on pegasos2 board but same situation). At least with qom-debug enabled (which I think is on by default unless explicitly disabled in configure) this will abort if the object is not the right type.
Quoted 4 lines
You're right that qom-cast-debug is enabled by default and that it causes
object_dynamic_cast_assert()to abort on type mismatch, but definitely not with a NULL value, as mentioned in this very old commit:
Indeed, PCI_BUS(NULL) does not abort just returns NULL. I think I remembered wrong and had dev==NULL so qdev_get_child_bus() was aborting.
Quoted 54 lines
commit
b7f43fe46029d8fd0594cd599fa2599dcce0f553Author: Paolo Bonzini <[email protected]> Date: Fri Nov 23 16:56:17 2012 +0100qom:
dynamic_castof NULL is always NULLTrying to cast a NULL value will cause a crash. Returning NULL is also sensible, and it is also what the type-unsafe
DO_UPCASTmacro does.Reported-by Markus Armbruster <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>Signed-off-by Anthony Liguori <[email protected]>Maybe this should be documented in the function header in "
qom/object.h".Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
shouldn't fail here.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/sam460ex.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/ppc/sam460ex.c +0
-0hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 388
Quoted 10 lines
hw/ppc/sam460ex.c +2
-5@@ -384,11 +384,8 @@ static void sam460ex_init(MachineState *machine)ppc460ex_pcie_init (env);/* All PCI irqs are connected to the same UIC pin (cf. UBoot source) */ dev =sysbus_create_simple ("ppc440-pcix-host" ,0xc0ec00000 , uic[1 ][0 ]); - pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci.0" ); -if (!pci_bus) { -error_report ("couldn't create PCI controller!" ); -exit (1 ); - } + pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); +But
PCI_BUS()is being passedqdev_get_child_bus(dev, "pci.0"), not dev... so the real question here is whether this can return NULL or not. And if this happens, is this a (1) user or (2) programming error ?Quoted 9 lines
Quoted 2 lines
If (1) then the "if (!pci_bus) { }" should be kept. If (2) then it should be converted to an
assert().I think it can only fail if the ppc440-pcix-host type is changed to not have a pci.0 child any more which is a programming error that's very unlikely to happen but if needed an assert could be added but I don't think that's really necessary. The
error_reportwas definitely not needed as it's not a user error in any case.
Quoted 2 lines
I was also thinking about a programming error. Whether to add an
assert()or not is up to you, you're the maintainer for this code :)
In that case I think I keep it simple and don't add an assert because I think this error is highly unlikely (we create a pci host object that should have a pci bus child) and it would crash anyway shortly when trying to add devices so an additional assert here does not seem to help much catching a bug.
Regards,
BALATON Zoltan