iommu/vt-d: break the for loop if an empty ir_ioapic entry found
PATCH 1/2 iommu/vt-d: break the for loop if an empty ir_ioapic entry found
No need to continue the loop after it has been found.
--- drivers/iommu/intel_irq_remapping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel_irq_remapping.c +3 -1
@@ -841,8 +841,10 @@ static int ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope,if (ir_ioapic[count].iommu == iommu && ir_ioapic[count].id == scope->enumeration_id)return 0 ; -else if (ir_ioapic[count].iommu ==NULL && free ==-1 ) +else if (ir_ioapic[count].iommu ==NULL && free ==-1 ) { free = count; +break ; + } }if (free ==-1 ) {pr_warn ("Exceeded Max IO APICS\n" );
Signature · 1 line
2.1.0
PATCH 2/2 iommu/vt-d: Adjsut the return value of the parse_ioapics_under_ir
Adjust the return value of parse_ioapics_under_ir as "-1" representing failure and "0" representing succcess. Just make it consistent with other function implementation, and we can judge if calling is successfull by if (!parse_ioapics_under_ir()) style.
--- drivers/iommu/intel_irq_remapping.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/intel_irq_remapping.c +3 -3
@@ -672,7 +672,7 @@ static int __init intel_prepare_irq_remapping(void)if (!dmar_ir_support ())return -ENODEV ; -if (parse_ioapics_under_ir () !=1 ) { +if (!parse_ioapics_under_ir ()) {pr_info ("Not enabling interrupt remapping\n" ); goto error; }
@@ -918,7 +918,7 @@ static int __init parse_ioapics_under_ir(void) }if (!ir_supported) -return 0 ; +return -1 ;for (ioapic_idx =0 ; ioapic_idx < nr_ioapics; ioapic_idx++) {int ioapic_id =mpc_ioapic_id (ioapic_idx);
@@ -930,7 +930,7 @@ static int __init parse_ioapics_under_ir(void) } } -return 1 ; +return 0 ; }static int __init ir_dev_scope_init (void )
Signature · 1 line
2.1.0
Joerg Roedel
maintainerRe: [PATCH 2/2] iommu/vt-d: Adjsut the return value of the parse_ioapics_under_ir
Quoted 23 lines · Baoquan He
drivers/iommu/intel_irq_remapping.c +2
-2@@ -672,7 +672,7 @@ static int __init intel_prepare_irq_remapping(void)if (!dmar_ir_support ())return -ENODEV ; -if (parse_ioapics_under_ir () !=1 ) { +if (!parse_ioapics_under_ir ()) {pr_info ("Not enabling interrupt remapping\n" ); goto error; }@@ -918,7 +918,7 @@ static int __init parse_ioapics_under_ir(void) }if (!ir_supported) -return 0 ; +return -1 ;for (ioapic_idx =0 ; ioapic_idx < nr_ioapics; ioapic_idx++) {int ioapic_id =mpc_ioapic_id (ioapic_idx);
drivers/iommu/intel_irq_remapping.c static int __init parse_ioapics_under_ir(void) · line 933
Quoted 5 lines
drivers/iommu/intel_irq_remapping.c +1
-1@@ -930,7 +930,7 @@ static int __init parse_ioapics_under_ir(void) } } -return 1 ; +return 0 ;
Looks good, but -ENODEV is probably a better return value than -1.
Joerg
Joerg Roedel
maintainerQuoted 12 lines · Baoquan He
No need to continue the loop after it has been found.
Signed-off-by Baoquan He <[email protected]>--- drivers/iommu/intel_irq_remapping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iommu/intel_irq_remapping.c +0
-0
drivers/iommu/intel_irq_remapping.c static int ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope, · line 848
Quoted 9 lines
drivers/iommu/intel_irq_remapping.c +3
-1@@ -841,8 +841,10 @@ static int ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope,if (ir_ioapic[count].iommu == iommu && ir_ioapic[count].id == scope->enumeration_id)return 0 ; -else if (ir_ioapic[count].iommu ==NULL && free ==-1 ) +else if (ir_ioapic[count].iommu ==NULL && free ==-1 ) { free = count; +break ; + } }
The purpose of the loop is also to avoid duplicate entries, so we need to search it till the end, no?
Joerg
Quoted 8 lines · Joerg Roedel
Quoted 7 lines · Baoquan He
No need to continue the loop after it has been found.
Signed-off-by Baoquan He <[email protected]>--- drivers/iommu/intel_irq_remapping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 16 lines
drivers/iommu/intel_irq_remapping.c static int ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope, > > if (ir_ioapic[count].iommu == iommu && · line 847
Quoted 13 lines
drivers/iommu/intel_irq_remapping.c +3
-1@@ -841,8 +841,10 @@ static int ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope, > > if (ir_ioapic[count].iommu == iommu && ir_ioapic[count].id == scope->enumeration_id)return 0 ; - else if (ir_ioapic[count].iommu == NULL && free == -1) + else if (ir_ioapic[count].iommu == NULL && free == -1) { free = count; +break ; + } }The purpose of the loop is also to avoid duplicate entries, so we need to search it till the end, no?
Ah, yes, you are right, it's on purpose. So I will drop this one and update the 2/2 only with your suggestion.