iommu: return early when devices in a group require different domain type
PATCH RESEND 1/3 iommu: return early when devices in a group require different domain type
When alloc default domain for an iommu_group in probe_alloc_default_domain, the expected domain type of each device in the iommu_group is checked in a loop, if two devices require different types, the loop can be broken since the default domain will be set to iommu_def_domain_type.
Return 1 when this happened to break the loop in __iommu_group_for_each_dev.
--- drivers/iommu/iommu.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/iommu.c +1 -0
@@ -1706,6 +1706,7 @@ static int probe_get_default_domain_type(struct device *dev, void *data)dev_name (gtype->dev), iommu_domain_type_str(gtype->type)); gtype->type =0 ; +return 1 ;/* end the outer loop */ }if (!gtype->dev) {
Signature · 1 line
2.17.1
PATCH RESEND 2/3 iommu: fix resource leak in iommu_group_alloc
When it fails to create file for reserved_regions and type of an iommu_group, the iommu_group_alloc returns ERR_PTR without releasing the iommu_group.
Add error handling to cleanup leaking resources.
--- drivers/iommu/iommu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +9 -2
@@ -734,15 +734,22 @@ struct iommu_group *iommu_group_alloc(void) ret =iommu_group_create_file (group, &iommu_group_attr_reserved_regions);if (ret) -return ERR_PTR (ret); + goto out_put_group; ret =iommu_group_create_file (group, &iommu_group_attr_type);if (ret) -return ERR_PTR (ret); + goto out_remove_file;pr_debug ("Allocated group %d\n" , group->id);return group; + +out_remove_file: +iommu_group_remove_file (group, &iommu_group_attr_reserved_regions); +out_put_group: +iommu_group_put (group); + +return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (iommu_group_alloc);
Signature · 1 line
2.17.1
PATCH RESEND 3/3 iommu/ioasid: Add missing new line for info message
In reply to Yuan CanA new line in the end of the log is expected, otherwise it will be mixed with later logs.
--- drivers/iommu/ioasid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/ioasid.c +1 -1
@@ -234,7 +234,7 @@ void ioasid_unregister_allocator(struct ioasid_allocator_ops *ops)rcu_assign_pointer (active_allocator,list_first_entry (&allocators_list, struct ioasid_allocator_data, list)); -pr_info ("IOASID allocator changed" ); +pr_info ("IOASID allocator changed.\n" ); }kfree_rcu (pallocator, rcu);break ;
Signature · 1 line
2.17.1
Quoted 8 lines · Yuan Can
When alloc default domain for an
iommu_groupinprobe_alloc_default_domain, the expected domain type of each device in theiommu_groupis checked in a loop, if two devices require different types, the loop can be broken since the default domain will be set toiommu_def_domain_type.
Return 1 when this happened to break the loop in__iommu_group_for_each_dev.
As I commented here
https://lore.kernel.org/linux-iommu/[email protected]/
Please use up the allowed number of characters per line before wrapping.
Best regards,
baolu
Quoted 10 lines · Baolu Lu
Quoted 8 lines · Yuan Can
When alloc default domain for an
iommu_groupinprobe_alloc_default_domain, the expected domain type of each device in theiommu_groupis checked in a loop, if two devices require different types, the loop can be broken since the default domain will be set toiommu_def_domain_type.
Return 1 when this happened to break the loop in__iommu_group_for_each_dev.
Quoted 7 lines
As I commented here
https://lore.kernel.org/linux-iommu/[email protected]/
Please use up the allowed number of characters per line before wrapping.
OK, thanks for the notice.
Best regards,
Yuan Can