npages is unsigned, so it will not be < 0 (line 138). julia ---------- Forwarded message ---------- Date: Wed, 18 Jan 2023 17:07:40 +0800 From: kernel test robot To: oe-kbuild@lists.linux.dev Cc: lkp@intel.com, Julia Lawall Subject: [ammarfaizi2-block:dhowells/linux-fs/iov-extract 14/32] fs/netfs/iterator.c:138:9-15: WARNING: Unsigned expression compared with zero: npages < 0 BCC: lkp@intel.com CC: oe-kbuild-all@lists.linux.dev CC: Ammar Faizi CC: "GNU/Weeb Mailing List" TO: David Howells tree: https://github.com/ammarfaizi2/linux-block dhowells/linux-fs/iov-extract head: ad732cfcd888e36990643e8b086d657fbaa87e6a commit: 8e2223898f436662ba84292f5235631944eb98e9 [14/32] netfs: Add a function to extract an iterator into a scatterlist :::::: branch date: 34 hours ago :::::: commit date: 34 hours ago config: riscv-randconfig-c034-20230115 compiler: riscv64-linux-gcc (GCC) 12.1.0 If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot | Reported-by: Julia Lawall cocci warnings: (new ones prefixed by >>) >> fs/netfs/iterator.c:138:9-15: WARNING: Unsigned expression compared with zero: npages < 0 vim +138 fs/netfs/iterator.c 8e2223898f4366 David Howells 2022-10-27 105 8e2223898f4366 David Howells 2022-10-27 106 /* 8e2223898f4366 David Howells 2022-10-27 107 * Extract as list of up to sg_max pages from UBUF- or IOVEC-class iterators, 8e2223898f4366 David Howells 2022-10-27 108 * pin or get refs on them appropriate and add them to the scatterlist. 8e2223898f4366 David Howells 2022-10-27 109 */ 8e2223898f4366 David Howells 2022-10-27 110 static ssize_t netfs_extract_user_to_sg(struct iov_iter *iter, 8e2223898f4366 David Howells 2022-10-27 111 ssize_t maxsize, 8e2223898f4366 David Howells 2022-10-27 112 struct sg_table *sgtable, 8e2223898f4366 David Howells 2022-10-27 113 unsigned int sg_max, 8e2223898f4366 David Howells 2022-10-27 114 unsigned int gup_flags) 8e2223898f4366 David Howells 2022-10-27 115 { 8e2223898f4366 David Howells 2022-10-27 116 struct scatterlist *sg = sgtable->sgl + sgtable->nents; 8e2223898f4366 David Howells 2022-10-27 117 struct page **pages; 8e2223898f4366 David Howells 2022-10-27 118 unsigned int npages; 8e2223898f4366 David Howells 2022-10-27 119 ssize_t ret = 0, res; 8e2223898f4366 David Howells 2022-10-27 120 size_t len, off; 8e2223898f4366 David Howells 2022-10-27 121 8e2223898f4366 David Howells 2022-10-27 122 /* We decant the page list into the tail of the scatterlist */ 8e2223898f4366 David Howells 2022-10-27 123 pages = (void *)sgtable->sgl + array_size(sg_max, sizeof(struct scatterlist)); 8e2223898f4366 David Howells 2022-10-27 124 pages -= sg_max; 8e2223898f4366 David Howells 2022-10-27 125 8e2223898f4366 David Howells 2022-10-27 126 do { 8e2223898f4366 David Howells 2022-10-27 127 res = iov_iter_extract_pages(iter, &pages, maxsize, sg_max, 8e2223898f4366 David Howells 2022-10-27 128 gup_flags, &off); 8e2223898f4366 David Howells 2022-10-27 129 if (res < 0) 8e2223898f4366 David Howells 2022-10-27 130 goto failed; 8e2223898f4366 David Howells 2022-10-27 131 8e2223898f4366 David Howells 2022-10-27 132 len = res; 8e2223898f4366 David Howells 2022-10-27 133 maxsize -= len; 8e2223898f4366 David Howells 2022-10-27 134 ret += len; 8e2223898f4366 David Howells 2022-10-27 135 npages = DIV_ROUND_UP(off + len, PAGE_SIZE); 8e2223898f4366 David Howells 2022-10-27 136 sg_max -= npages; 8e2223898f4366 David Howells 2022-10-27 137 8e2223898f4366 David Howells 2022-10-27 @138 for (; npages < 0; npages--) { 8e2223898f4366 David Howells 2022-10-27 139 struct page *page = *pages; 8e2223898f4366 David Howells 2022-10-27 140 size_t seg = min_t(size_t, PAGE_SIZE - off, len); 8e2223898f4366 David Howells 2022-10-27 141 8e2223898f4366 David Howells 2022-10-27 142 *pages++ = NULL; 8e2223898f4366 David Howells 2022-10-27 143 sg_set_page(sg, page, len, off); 8e2223898f4366 David Howells 2022-10-27 144 sgtable->nents++; 8e2223898f4366 David Howells 2022-10-27 145 sg++; 8e2223898f4366 David Howells 2022-10-27 146 len -= seg; 8e2223898f4366 David Howells 2022-10-27 147 off = 0; 8e2223898f4366 David Howells 2022-10-27 148 } 8e2223898f4366 David Howells 2022-10-27 149 } while (maxsize > 0 && sg_max > 0); 8e2223898f4366 David Howells 2022-10-27 150 8e2223898f4366 David Howells 2022-10-27 151 return ret; 8e2223898f4366 David Howells 2022-10-27 152 8e2223898f4366 David Howells 2022-10-27 153 failed: 8e2223898f4366 David Howells 2022-10-27 154 while (sgtable->nents > sgtable->orig_nents) 8e2223898f4366 David Howells 2022-10-27 155 put_page(sg_page(&sgtable->sgl[--sgtable->nents])); 8e2223898f4366 David Howells 2022-10-27 156 return res; 8e2223898f4366 David Howells 2022-10-27 157 } 8e2223898f4366 David Howells 2022-10-27 158 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests