softmmu/physmem: Hint notifier is not NULL in as_translate_for_iotlb()
PATCH 1/1 softmmu/physmem: Hint notifier is not NULL in as_translate_for_iotlb()
When using GCC 10.2 configured with --extra-cflags=-Os, we get:
softmmu/physmem.c: In function ‘address_space_translate_for_iotlb’:
softmmu/physmem.c:643:26: error: ‘notifier’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
643 | notifier->active = true;
| ^
softmmu/physmem.c:608:23: note: ‘notifier’ was declared here
608 | TCGIOMMUNotifier *notifier;
| ^~~~~~~~Insert assertions as hint to the compiler that 'notifier' can not be NULL there.
---
Yet another hole in our CI.
--- softmmu/physmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
softmmu/physmem.c +2 -1
@@ -605,7 +605,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,* when the IOMMU tells us the mappings we've cached have changed. */ MemoryRegion *mr =MEMORY_REGION (iommu_mr); -TCGIOMMUNotifier *notifier; +TCGIOMMUNotifier *notifier =NULL ;int i;for (i =0 ; i < cpu->iommu_notifiers->len; i++) {
@@ -638,6 +638,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,memory_region_register_iommu_notifier (notifier->mr, ¬ifier->n, &error_fatal); } +assert (notifier !=NULL );if (!notifier->active) { notifier->active = true;
Signature · 1 line
2.26.2
Quoted 35 lines · Philippe Mathieu-Daudé
When using GCC 10.2 configured with --extra-cflags=-Os, we get:
softmmu/physmem.c: In function ‘address_space_translate_for_iotlb’:
softmmu/physmem.c:643:26: error: ‘notifier’ may be used uninitialized in this function [-Werror=maybe-uninitialized]643 | notifier->active = true; | ^ softmmu/physmem.c:608:23: note: ‘notifier’ was declared here 608 | TCGIOMMUNotifier *notifier; | ^~~~~~~~Insert assertions as hint to the compiler that 'notifier' can not be NULL there.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Yet another hole in our CI.--- softmmu/physmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)softmmu/physmem.c +1
-1@@ -605,7 +605,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,* when the IOMMU tells us the mappings we've cached have changed. */ MemoryRegion *mr =MEMORY_REGION (iommu_mr); -TCGIOMMUNotifier *notifier; +TCGIOMMUNotifier *notifier =NULL ;int i;for (i =0 ; i < cpu->iommu_notifiers->len; i++) {
softmmu/physmem.c static void tcg_register_iommu_notifier(CPUState *cpu, · line 644
Quoted 7 lines
softmmu/physmem.c +1
-0@@ -638,6 +638,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,memory_region_register_iommu_notifier (notifier->mr, ¬ifier->n, &error_fatal); } +assert (notifier !=NULL );if (!notifier->active) { notifier->active = true;
Is the assert() necessary to prevent the compiler complaining? Usually we don't bother if it's about to be dereferenced anyway.
thanks
-- PMM
Quoted 41 lines · Peter Maydell
Quoted 40 lines · Philippe Mathieu-Daudé
When using GCC 10.2 configured with --extra-cflags=-Os, we get:
softmmu/physmem.c: In function ‘address_space_translate_for_iotlb’:
softmmu/physmem.c:643:26: error: ‘notifier’ may be used uninitialized in this function [-Werror=maybe-uninitialized]643 | notifier->active = true; | ^ softmmu/physmem.c:608:23: note: ‘notifier’ was declared here 608 | TCGIOMMUNotifier *notifier; | ^~~~~~~~Insert assertions as hint to the compiler that 'notifier' can not be NULL there.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Yet another hole in our CI.--- softmmu/physmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)softmmu/physmem.c +2
-1@@ -605,7 +605,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,* when the IOMMU tells us the mappings we've cached have changed. */ MemoryRegion *mr =MEMORY_REGION (iommu_mr); -TCGIOMMUNotifier *notifier; +TCGIOMMUNotifier *notifier =NULL ;int i;for (i =0 ; i < cpu->iommu_notifiers->len; i++) {@@ -638,6 +638,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,memory_region_register_iommu_notifier (notifier->mr, ¬ifier->n, &error_fatal); } +assert (notifier !=NULL );
Quoted 5 lines
softmmu/physmem.c static void tcg_register_iommu_notifier(CPUState *cpu, · line 644
Quoted 2 lines
softmmu/physmem.c +0
-0if (!notifier->active) { notifier->active = true;Is the
assert()necessary to prevent the compiler complaining? Usually we don't bother if it's about to be dereferenced anyway.
Yes you are right, the assert() is not necessary. Simply initializing the value silents the error.
Regards,
Phil.