Staging: iommu: Replace null pointer check with IS_ERR in arm_smmu_domain_alloc_user()
Subsystems (2)
PATCH 1/1 Staging: iommu: Replace null pointer check with IS_ERR in arm_smmu_domain_alloc_user()
The smatch reported following:
'''drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3065 arm_smmu_domain_alloc_user() warn: 'smmu_domain' is an error pointer or valid drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3068 arm_smmu_domain_alloc_user() error: 'smmu_domain' dereferencing possible ERR_PTR() '''
The function arm_smmu_domain_alloc() handles the null pointer after kzalloc and returns ERR_PTR(-ENOMEM).
Replacing condition check !smmu_domain with IS_ERR(smmu_domain) and returning smmu_domain.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -2
@@ -3062,8 +3062,8 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,return ERR_PTR (-EOPNOTSUPP ); smmu_domain =arm_smmu_domain_alloc (); -if (!smmu_domain) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (smmu_domain)) +return smmu_domain; smmu_domain->domain.type =IOMMU_DOMAIN_UNMANAGED ; smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops;
Signature · 1 line
2.43.0
Quoted 11 lines · Dipendra Khadka
The smatch reported following:
'''drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3065arm_smmu_domain_alloc_user()warn: 'smmu_domain' is an error pointer or validdrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3068arm_smmu_domain_alloc_user()error: 'smmu_domain' dereferencing possibleERR_PTR()'''The function
arm_smmu_domain_alloc()handles the null pointer after kzalloc and returnsERR_PTR(-ENOMEM).Replacing condition check !smmu_domain with
IS_ERR(smmu_domain)and returningsmmu_domain.
Hi Dipendra,
Thanks for looking into the code. However, I think this was fixed last month by Dan's patch [1] and has been merged in the master branch. Please pull the latest. :)
[1]
https://lore.kernel.org/linux-arm-kernel/[email protected]/T/
Quoted 11 lines
Signed-off-by Dipendra Khadka <[email protected]>--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +0
-0
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c arm_smmu_domain_alloc_user(struct device *dev, u32 flags, · line 3066
Quoted 7 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2
-2@@ -3062,8 +3062,8 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,return ERR_PTR (-EOPNOTSUPP ); smmu_domain =arm_smmu_domain_alloc (); -if (!smmu_domain) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (smmu_domain)) +return smmu_domain;
Quick note, using something like ERR_CAST is better in such cases.
Quoted 7 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +0
-0smmu_domain->domain.type =IOMMU_DOMAIN_UNMANAGED ; smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops;Signature · 1 line
2.43.0
Thanks,
Pranjal
Hi Pranjal,
Quoted 14 lines · Pranjal Shrivastava
Quoted 11 lines · Dipendra Khadka
The smatch reported following:
'''drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3065arm_smmu_domain_alloc_user()warn: 'smmu_domain' is an error pointer or validdrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3068arm_smmu_domain_alloc_user()error: 'smmu_domain' dereferencing possibleERR_PTR()'''The function
arm_smmu_domain_alloc()handles the null pointer after kzalloc and returnsERR_PTR(-ENOMEM).Replacing condition check !smmu_domain with
IS_ERR(smmu_domain)and returningsmmu_domain.
Quoted 9 lines
Hi Dipendra,
Thanks for looking into the code. However, I think this was fixed last month by Dan's patch [1] and has been merged in the master branch. Please pull the latest. :)
[1]
https://lore.kernel.org/linux-arm-kernel/[email protected]/T/
I just checked on the staging-next. I will make sure to check on this tree as well.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Dipendra Khadka <[email protected]>--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +0
-0@@ -3062,8 +3062,8 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,return ERR_PTR (-EOPNOTSUPP );
Quoted 8 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c arm_smmu_domain_alloc_user(struct device *dev, u32 flags, · line 3066
Quoted 5 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2
-2smmu_domain =arm_smmu_domain_alloc (); -if (!smmu_domain) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (smmu_domain)) +return smmu_domain;Quick note, using something like
ERR_CASTis better in such cases.
Thanks a lot for the knowledge.
Quoted 10 lines
Quoted 7 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +0
-1smmu_domain->domain.type =IOMMU_DOMAIN_UNMANAGED ; smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops; --2.43.0
Thanks,
Pranjal
Thanks,
Dipendra Khadka
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Dipendra,
kernel test robot noticed the following build errors:
[auto build test ERROR on staging/staging-testing]
url: https://github.com/intel-lab-lkp/linux/commits/Dipendra-Khadka/Staging-iommu-Replace-null-pointer-check-with-IS_ERR-in-arm_smmu_domain_alloc_user/20240922-235756 base: staging/staging-testing patch link: https://lore.kernel.org/r/20240922155621.49432-1-kdipendra88%40gmail.com patch subject: [PATCH] Staging: iommu: Replace null pointer check with IS_ERR in arm_smmu_domain_alloc_user() config: arm64-randconfig-001-20240925 (https://download.01.org/0day-ci/archive/20240925/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240925/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c: In function 'arm_smmu_domain_alloc_user':
>> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3066:24: error: returning 'struct arm_smmu_domain *' from a function with incompatible return type 'struct iommu_domain *' [-Wincompatible-pointer-types]
3066 | return smmu_domain;
| ^~~~~~~~~~~vim +3066 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
3048
3049 static struct iommu_domain *
3050 arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
3051 struct iommu_domain *parent,
3052 const struct iommu_user_data *user_data)
3053 {
3054 struct arm_smmu_master *master = dev_iommu_priv_get(dev);
3055 const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
3056 struct arm_smmu_domain *smmu_domain;
3057 int ret;
3058
3059 if (flags & ~PAGING_FLAGS)
3060 return ERR_PTR(-EOPNOTSUPP);
3061 if (parent || user_data)
3062 return ERR_PTR(-EOPNOTSUPP);
3063
3064 smmu_domain = arm_smmu_domain_alloc();
3065 if (IS_ERR(smmu_domain))
> 3066 return smmu_domain;
3067
3068 smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED;
3069 smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops;
3070 ret = arm_smmu_domain_finalise(smmu_domain, master->smmu, flags);
3071 if (ret)
3072 goto err_free;
3073 return &smmu_domain->domain;
3074
3075 err_free:
3076 kfree(smmu_domain);
3077 return ERR_PTR(ret);
3078 }
3079
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Dipendra,
kernel test robot noticed the following build errors:
[auto build test ERROR on staging/staging-testing]
url: https://github.com/intel-lab-lkp/linux/commits/Dipendra-Khadka/Staging-iommu-Replace-null-pointer-check-with-IS_ERR-in-arm_smmu_domain_alloc_user/20240922-235756 base: staging/staging-testing patch link: https://lore.kernel.org/r/20240922155621.49432-1-kdipendra88%40gmail.com patch subject: [PATCH] Staging: iommu: Replace null pointer check with IS_ERR in arm_smmu_domain_alloc_user() config: arm64-randconfig-003-20240925 (https://download.01.org/0day-ci/archive/20240925/[email protected]/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 7773243d9916f98ba0ffce0c3a960e4aa9f03e81) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240925/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:15:
In file included from include/linux/crash_dump.h:5:
In file included from include/linux/kexec.h:18:
In file included from include/linux/vmcore_info.h:6:
In file included from include/linux/elfcore.h:11:
In file included from include/linux/ptrace.h:10:
In file included from include/linux/pid_namespace.h:7:
In file included from include/linux/mm.h:2228:
include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
514 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3066:10: error: incompatible pointer types returning 'struct arm_smmu_domain *' from a function with result type 'struct iommu_domain *' [-Werror,-Wincompatible-pointer-types]
3066 | return smmu_domain;
| ^~~~~~~~~~~1 warning and 1 error generated.
vim +3066 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
3048
3049 static struct iommu_domain *
3050 arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
3051 struct iommu_domain *parent,
3052 const struct iommu_user_data *user_data)
3053 {
3054 struct arm_smmu_master *master = dev_iommu_priv_get(dev);
3055 const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
3056 struct arm_smmu_domain *smmu_domain;
3057 int ret;
3058
3059 if (flags & ~PAGING_FLAGS)
3060 return ERR_PTR(-EOPNOTSUPP);
3061 if (parent || user_data)
3062 return ERR_PTR(-EOPNOTSUPP);
3063
3064 smmu_domain = arm_smmu_domain_alloc();
3065 if (IS_ERR(smmu_domain))
> 3066 return smmu_domain;
3067
3068 smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED;
3069 smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops;
3070 ret = arm_smmu_domain_finalise(smmu_domain, master->smmu, flags);
3071 if (ret)
3072 goto err_free;
3073 return &smmu_domain->domain;
3074
3075 err_free:
3076 kfree(smmu_domain);
3077 return ERR_PTR(ret);
3078 }
3079
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki