[v2,1/2] iommu/vt-d: Handle the failure case of dmar_reenable_qi()

Message ID 20230602020520.224465-2-yanfei.xu@intel.com
State New
Headers
Series Misc cleanup for iommu/vt-d |

Commit Message

Yanfei Xu June 2, 2023, 2:05 a.m. UTC
  dmar_reenable_qi() may not succeed. Check and return when it fails.

Signed-off-by: Yanfei Xu <yanfei.xu@intel.com>
---
 drivers/iommu/intel/iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Robin Murphy June 2, 2023, 9:27 a.m. UTC | #1
On 2023-06-02 03:05, Yanfei Xu wrote:
> dmar_reenable_qi() may not succeed. Check and return when it fails.
> 
> Signed-off-by: Yanfei Xu <yanfei.xu@intel.com>
> ---
>   drivers/iommu/intel/iommu.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index 8096273b034c..e9188d045609 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -2967,10 +2967,14 @@ static int init_iommu_hw(void)
>   {
>   	struct dmar_drhd_unit *drhd;
>   	struct intel_iommu *iommu = NULL;
> +	int ret;
>   
> -	for_each_active_iommu(iommu, drhd)
> +	for_each_active_iommu(iommu, drhd) {
>   		if (iommu->qi)
> -			dmar_reenable_qi(iommu);
> +			ret = dmar_reenable_qi(iommu);
> +		if (ret)

Nit: either this should be inside the previous condition, or you need to 
initialise ret to 0.

Thanks,
Robin.

> +			return ret;
> +	}
>   
>   	for_each_iommu(iommu, drhd) {
>   		if (drhd->ignored) {
  
Yanfei Xu June 2, 2023, 10:06 a.m. UTC | #2
On 6/2/2023 5:27 PM, Robin Murphy wrote:
> On 2023-06-02 03:05, Yanfei Xu wrote:
>> dmar_reenable_qi() may not succeed. Check and return when it fails.
>>
>> Signed-off-by: Yanfei Xu <yanfei.xu@intel.com>
>> ---
>>   drivers/iommu/intel/iommu.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
>> index 8096273b034c..e9188d045609 100644
>> --- a/drivers/iommu/intel/iommu.c
>> +++ b/drivers/iommu/intel/iommu.c
>> @@ -2967,10 +2967,14 @@ static int init_iommu_hw(void)
>>   {
>>       struct dmar_drhd_unit *drhd;
>>       struct intel_iommu *iommu = NULL;
>> +    int ret;
>>   -    for_each_active_iommu(iommu, drhd)
>> +    for_each_active_iommu(iommu, drhd) {
>>           if (iommu->qi)
>> -            dmar_reenable_qi(iommu);
>> +            ret = dmar_reenable_qi(iommu);
>> +        if (ret)
>
> Nit: either this should be inside the previous condition, or you need 
> to initialise ret to 0.
>
Oh, you are right. Will correct it.

Thanks,
Yanfei

> Thanks,
> Robin.
>
>> +            return ret;
>> +    }
>>         for_each_iommu(iommu, drhd) {
>>           if (drhd->ignored) {
  

Patch

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 8096273b034c..e9188d045609 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2967,10 +2967,14 @@  static int init_iommu_hw(void)
 {
 	struct dmar_drhd_unit *drhd;
 	struct intel_iommu *iommu = NULL;
+	int ret;
 
-	for_each_active_iommu(iommu, drhd)
+	for_each_active_iommu(iommu, drhd) {
 		if (iommu->qi)
-			dmar_reenable_qi(iommu);
+			ret = dmar_reenable_qi(iommu);
+		if (ret)
+			return ret;
+	}
 
 	for_each_iommu(iommu, drhd) {
 		if (drhd->ignored) {