iommu:Check that iommu_device_create has completed successfully in alloc_iommu
PATCH 1/1 iommu:Check that iommu_device_create has completed successfully in alloc_iommu
This adds the proper check to alloc_iommu to make sure that the call to iommu_device_create has completed successfully and if not return to the caller the error code returned after freeing up resources allocated previously by alloc_iommu.
--- drivers/iommu/dmar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iommu/dmar.c +4 -1
@@ -1069,9 +1069,12 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) iommu->iommu_dev =iommu_device_create (NULL , iommu, intel_iommu_groups,"%s" , iommu->name); +if (IS_ERR (iommu->iommu_dev)) { + err =PTR_ERR (iommu->iommu_dev); + goto err_unmap; + }return 0 ; - err_unmap:unmap_iommu (iommu); error_free_seq_id:
Signature · 1 line
2.5.0
2015-12-29 13:10 GMT+08:00 Nicholas Krause <[email protected]>:
Quoted 15 lines
This adds the proper check to
alloc_iommuto make sure that the call toiommu_device_createhas completed successfully and if not return to the caller the error code returned after freeing up resources allocated previously byalloc_iommu.Signed-off-by Nicholas Krause <[email protected]>--- drivers/iommu/dmar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iommu/dmar.c +0
-0
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit *drhd) · line 1075
Quoted 7 lines
drivers/iommu/dmar.c +4
-0@@ -1069,9 +1069,12 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) iommu->iommu_dev =iommu_device_create (NULL , iommu, intel_iommu_groups,"%s" , iommu->name); +if (IS_ERR (iommu->iommu_dev)) { + err =PTR_ERR (iommu->iommu_dev); + goto err_unmap; + }
If so, will this bad 'iommu->iommu_dev' break your iommu work? It seems not necessary.
Quoted 13 lines
drivers/iommu/dmar.c +0
-2return 0 ; - err_unmap:unmap_iommu (iommu); error_free_seq_id: --2.5.0
_______________________________________________
iommu mailing list iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Signature · 3 lines
--- Vincent Wan(Zongshun) www.mcuos.com
A message that is not in the archive (sent off-list or not yet received): CAKT61h-n6=enWPAmEkPE36VZvrGFn9_Zj0y4+DdkOB33jyELUw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 11 lines · Wan ZongShun
2015-12-29 13:10 GMT+08:00 Nicholas Krause <[email protected]>:
Quoted 10 lines
This adds the proper check to
alloc_iommuto make sure that the call toiommu_device_createhas completed successfully and if not return to the caller the error code returned after freeing up resources allocated previously byalloc_iommu.Signed-off-by Nicholas Krause <[email protected]>--- drivers/iommu/dmar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 16 lines
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit *drhd) · line 1075
Quoted 12 lines
drivers/iommu/dmar.c +4
-0@@ -1069,9 +1069,12 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) iommu->iommu_dev =iommu_device_create (NULL , iommu, intel_iommu_groups,"%s" , iommu->name); +if (IS_ERR (iommu->iommu_dev)) { + err =PTR_ERR (iommu->iommu_dev); + goto err_unmap; + }If so, will this bad '
iommu->iommu_dev' break your iommu work? It seems not necessary.
My concern is that if the iommu device is allocated successfully but not loaded successfully into sysfs does this not make the device useless to some degree and therefore there is no point in having this device being allocated without it's information being exported in sysfs. Again if it's fine without being exported in sysfs that's fine and in that case we should at least print to the console with KERN_CRIT in order to warn of this critical error to the user. Again I took the first approach but if you/the maintainer Joerg Roedel feel that the second idea is better I will be glad to send a patch doing that :). There are also other callers doing this as I found here so depending on how we solve this one I will do the others in a patch series:
http://lxr.free-electrons.com/ident?i=iommu_device_create
Hopes that this explains the patch,
Nick
Quoted 16 lines
Quoted 13 lines
drivers/iommu/dmar.c +0
-2return 0 ; - err_unmap:unmap_iommu (iommu); error_free_seq_id: --2.5.0
_______________________________________________
iommu mailing list iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 15 lines · Nicholas Krause
This adds the proper check to
alloc_iommuto make sure that the call toiommu_device_createhas completed successfully and if not return to the caller the error code returned after freeing up resources allocated previously byalloc_iommu.Signed-off-by Nicholas Krause <[email protected]>--- drivers/iommu/dmar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iommu/dmar.c +0
-0
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit *drhd) · line 1075
Quoted 7 lines
drivers/iommu/dmar.c +4
-0@@ -1069,9 +1069,12 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) iommu->iommu_dev =iommu_device_create (NULL , iommu, intel_iommu_groups,"%s" , iommu->name); +if (IS_ERR (iommu->iommu_dev)) { + err =PTR_ERR (iommu->iommu_dev); + goto err_unmap; + }
This leaves a dangling pointer to the iommu in drhd->iommu.
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit *drhd) · line 1074
Quoted 3 lines
drivers/iommu/dmar.c +0
-1return 0 ; -
That blank line improves readability of the code, please leave it in.
Quoted 3 lines
drivers/iommu/dmar.c +0
-0err_unmap:unmap_iommu (iommu); error_free_seq_id:
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 17 lines · Joerg Roedel
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit
Quoted 15 lines · Nicholas Krause
This adds the proper check to
alloc_iommuto make sure that the call toiommu_device_createhas completed successfully and if not return to the caller the error code returned after freeing up resources allocated previously byalloc_iommu.Signed-off-by Nicholas Krause <[email protected]>--- drivers/iommu/dmar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iommu/dmar.c +0
-0@@ -1069,9 +1069,12 @@ static int alloc_iommu(struct dmar_drhd_unit*drhd)
Quoted 9 lines
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit *drhd) · line 1075
Quoted 7 lines
drivers/iommu/dmar.c +4
-0iommu->iommu_dev =iommu_device_create (NULL , iommu, intel_iommu_groups,"%s" , iommu->name); +if (IS_ERR (iommu->iommu_dev)) { + err =PTR_ERR (iommu->iommu_dev); + goto err_unmap; + }This leaves a dangling pointer to the iommu in
drhd->iommu.
Yes that's true and was wondering if you want me to fix it up to set the pointer back to null first or if preferred around safe state.
Nick
Quoted 10 lines
drivers/iommu/dmar.c static int alloc_iommu(struct dmar_drhd_unit *drhd) · line 1074
Quoted 4 lines
drivers/iommu/dmar.c +0
-1return 0 ; -That blank line improves readability of the code, please leave it in.
Quoted 3 lines
drivers/iommu/dmar.c +0
-0err_unmap:unmap_iommu (iommu); error_free_seq_id:
Joerg Roedel
maintainerQuoted 2 lines · Nicholas Krause
Yes that's true and was wondering if you want me to fix it up to set the pointer back to null first or if preferred around safe state.
The best solution is to set the dmar->iommu pointer after the error check for iommu_device_create().
Joerg