[jgunthorpe:iommufd 10/12] drivers/iommu/iommufd/vfio_compat.c:358:3: warning: Value stored to 'rc' is never read [clang-analyzer-deadcode.DeadStores]

From: kernel test robot
Date: Wed Mar 09 2022 - 00:53:24 EST


tree: https://github.com/jgunthorpe/linux iommufd
head: 446626304259cf3deb4a4799b42a909bea0bc070
commit: 6df3783f55eb10f5583783566fd12646ef693568 [10/12] iommufd: vfio container FD ioctl compatibility
config: mips-randconfig-c004-20220227 (https://download.01.org/0day-ci/archive/20220301/202203010007.dMWQzNHZ-lkp@xxxxxxxxx/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/jgunthorpe/linux/commit/6df3783f55eb10f5583783566fd12646ef693568
git remote add jgunthorpe https://github.com/jgunthorpe/linux
git fetch --no-tags jgunthorpe iommufd
git checkout 6df3783f55eb10f5583783566fd12646ef693568
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips clang-analyzer

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <yujie.liu@xxxxxxxxx>


clang-analyzer warnings: (new ones prefixed by >>)

>> drivers/iommu/iommufd/vfio_compat.c:358:3: warning: Value stored to 'rc' is never read [clang-analyzer-deadcode.DeadStores]
rc = -EFAULT;
^ ~~~~~~~

vim +/rc +358 drivers/iommu/iommufd/vfio_compat.c

6df3783f55eb10 Jason Gunthorpe 2021-12-15 291
6df3783f55eb10 Jason Gunthorpe 2021-12-15 292 static int iommufd_vfio_iommu_get_info(struct iommufd_ctx *ictx,
6df3783f55eb10 Jason Gunthorpe 2021-12-15 293 void __user *arg)
6df3783f55eb10 Jason Gunthorpe 2021-12-15 294 {
6df3783f55eb10 Jason Gunthorpe 2021-12-15 295 typedef int (*fill_cap_fn)(struct iommufd_ioas *ioas,
6df3783f55eb10 Jason Gunthorpe 2021-12-15 296 struct vfio_info_cap_header __user *cur,
6df3783f55eb10 Jason Gunthorpe 2021-12-15 297 size_t avail);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 298 static const fill_cap_fn fill_fns[] = {
6df3783f55eb10 Jason Gunthorpe 2021-12-15 299 iommufd_fill_cap_iova,
6df3783f55eb10 Jason Gunthorpe 2021-12-15 300 iommufd_fill_cap_dma_avail,
6df3783f55eb10 Jason Gunthorpe 2021-12-15 301 };
6df3783f55eb10 Jason Gunthorpe 2021-12-15 302 size_t minsz = offsetofend(struct vfio_iommu_type1_info, iova_pgsizes);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 303 struct vfio_info_cap_header __user *last_cap = NULL;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 304 struct vfio_iommu_type1_info info;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 305 struct iommufd_ioas *ioas;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 306 size_t total_cap_size;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 307 int rc;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 308 int i;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 309
6df3783f55eb10 Jason Gunthorpe 2021-12-15 310 if (copy_from_user(&info, arg, minsz))
6df3783f55eb10 Jason Gunthorpe 2021-12-15 311 return -EFAULT;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 312
6df3783f55eb10 Jason Gunthorpe 2021-12-15 313 if (info.argsz < minsz)
6df3783f55eb10 Jason Gunthorpe 2021-12-15 314 return -EINVAL;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 315 minsz = min_t(size_t, info.argsz, sizeof(info));
6df3783f55eb10 Jason Gunthorpe 2021-12-15 316
6df3783f55eb10 Jason Gunthorpe 2021-12-15 317 ioas = get_compat_ioas(ictx);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 318 if (IS_ERR(ioas))
6df3783f55eb10 Jason Gunthorpe 2021-12-15 319 return PTR_ERR(ioas);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 320
6df3783f55eb10 Jason Gunthorpe 2021-12-15 321 down_read(&ioas->iopt.iova_rwsem);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 322 info.flags = VFIO_IOMMU_INFO_PGSIZES;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 323 info.iova_pgsizes = iommufd_get_pagesizes(ioas);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 324 info.cap_offset = 0;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 325
6df3783f55eb10 Jason Gunthorpe 2021-12-15 326 total_cap_size = sizeof(info);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 327 for (i = 0; i != ARRAY_SIZE(fill_fns); i++) {
6df3783f55eb10 Jason Gunthorpe 2021-12-15 328 int cap_size;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 329
6df3783f55eb10 Jason Gunthorpe 2021-12-15 330 if (info.argsz > total_cap_size)
6df3783f55eb10 Jason Gunthorpe 2021-12-15 331 cap_size = fill_fns[i](ioas, arg + total_cap_size,
6df3783f55eb10 Jason Gunthorpe 2021-12-15 332 info.argsz - total_cap_size);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 333 else
6df3783f55eb10 Jason Gunthorpe 2021-12-15 334 cap_size = fill_fns[i](ioas, NULL, 0);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 335 if (cap_size < 0) {
6df3783f55eb10 Jason Gunthorpe 2021-12-15 336 rc = cap_size;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 337 goto out_put;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 338 }
6df3783f55eb10 Jason Gunthorpe 2021-12-15 339 if (last_cap && info.argsz >= total_cap_size &&
6df3783f55eb10 Jason Gunthorpe 2021-12-15 340 put_user(total_cap_size, &last_cap->next)) {
6df3783f55eb10 Jason Gunthorpe 2021-12-15 341 rc = -EFAULT;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 342 goto out_put;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 343 }
6df3783f55eb10 Jason Gunthorpe 2021-12-15 344 last_cap = arg + total_cap_size;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 345 total_cap_size += cap_size;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 346 }
6df3783f55eb10 Jason Gunthorpe 2021-12-15 347
6df3783f55eb10 Jason Gunthorpe 2021-12-15 348 /*
6df3783f55eb10 Jason Gunthorpe 2021-12-15 349 * If the user did not provide enough space then only some caps are
6df3783f55eb10 Jason Gunthorpe 2021-12-15 350 * returned and the argsz will be updated to the correct amount to get
6df3783f55eb10 Jason Gunthorpe 2021-12-15 351 * all caps.
6df3783f55eb10 Jason Gunthorpe 2021-12-15 352 */
6df3783f55eb10 Jason Gunthorpe 2021-12-15 353 if (info.argsz >= total_cap_size)
6df3783f55eb10 Jason Gunthorpe 2021-12-15 354 info.cap_offset = sizeof(info);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 355 info.argsz = total_cap_size;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 356 info.flags |= VFIO_IOMMU_INFO_CAPS;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 357 if (copy_to_user(arg, &info, minsz))
6df3783f55eb10 Jason Gunthorpe 2021-12-15 @358 rc = -EFAULT;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 359 rc = 0;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 360
6df3783f55eb10 Jason Gunthorpe 2021-12-15 361 out_put:
6df3783f55eb10 Jason Gunthorpe 2021-12-15 362 up_read(&ioas->iopt.iova_rwsem);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 363 iommufd_put_object(&ioas->obj);
6df3783f55eb10 Jason Gunthorpe 2021-12-15 364 return rc;
6df3783f55eb10 Jason Gunthorpe 2021-12-15 365 }
6df3783f55eb10 Jason Gunthorpe 2021-12-15 366

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx