iommufd: Fix uninitialized rc in iommufd_access_rw()
PATCH 1/1 iommufd: Fix uninitialized rc in iommufd_access_rw()
Reported by smatch:drivers/iommu/iommufd/device.c:1392 iommufd_access_rw() error: uninitialized symbol 'rc'.
Fixes 8d40205f6093 ("iommufd: Add kAPI toward external drivers for kernel access")
Reported-by kernel test robot <[email protected]>
Reported-by Dan Carpenter <[email protected]>
[nicolinc: can't find an original report but only in "old smatch warnings"]
Signed-off-by Nicolin Chen <[email protected]>
--- drivers/iommu/iommufd/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iommufd/device.c +1 -1
@@ -1348,7 +1348,7 @@ int iommufd_access_rw(struct iommufd_access *access, unsigned long iova,struct io_pagetable *iopt;struct iopt_area *area;unsigned long last_iova; -int rc; +int rc =0 ;if (!length)return -EINVAL ;
Signature · 1 line
2.34.1
Jason Gunthorpe
maintainerQuoted 19 lines · Nicolin Chen
Reported by smatch:
drivers/iommu/iommufd/device.c:1392iommufd_access_rw()error: uninitialized symbol 'rc'.Fixes 8d40205f6093 ("iommufd: Add kAPI toward external drivers for kernel access")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>[nicolinc: can't find an original report but only in "old smatch warnings"]Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/iommufd/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/iommufd/device.c +0
-0
drivers/iommu/iommufd/device.c int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, · line 1351
Quoted 5 lines
drivers/iommu/iommufd/device.c +1
-1@@ -1348,7 +1348,7 @@ int iommufd_access_rw(struct iommufd_access *access, unsigned long iova,struct io_pagetable *iopt;struct iopt_area *area;unsigned long last_iova; -int rc; +int rc =0 ;
This is a smatch error but it can't actually happen because:
if (!length)
return -EINVAL;
And:
if (!iopt_area_contig_done(&iter)) rc = -ENOENT;
Prevents an empty loop for iopt_for_each_contig_area()
And each loop does:
rc = iopt_pages_rw_access(
Which will zero rc.
If for some reason rc was used uninitialized then it would be an error so it should be rc = -EINVAL. I fixed it up.
Jason