[dhowells-fs:netfs-next 13/29] fs/netfs/iterator.c:137:26-35: WARNING: Unsigned expression compared with zero: max_pages > 0
kernel test robot <[email protected]> Sat, 25 Jul 2026 03:55:52 +0800
| Newsgroups | dev.linux.lists.oe-kbuild |
|---|---|
| Message-ID | <[email protected]> |
BCC: [email protected] CC: [email protected] TO: David Howells <[email protected]> tree: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git netfs-next head: ddfc7002233eb9ca7143c363820b7480d5f705de commit: d7c4f8b0f2c278af9e4e4d548ad71be933507f75 [13/29] netfs: Add a function to extract from an iter into a bvecq :::::: branch date: 2 days ago :::::: commit date: 2 days ago config: i386-randconfig-r052-20260724 (https://download.01.org/0day-ci/archive/20260725/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 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]> | Reported-by: Julia Lawall <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/ cocci warnings: (new ones prefixed by >>) >> fs/netfs/iterator.c:137:26-35: WARNING: Unsigned expression compared with zero: max_pages > 0 vim +137 fs/netfs/iterator.c 85dd2c8ff368b1 David Howells 2022-10-20 15 d7c4f8b0f2c278 David Howells 2026-01-07 16 /** d7c4f8b0f2c278 David Howells 2026-01-07 17 * netfs_extract_iter - Extract virtually contiguous pages from an iterator into a bvecq d7c4f8b0f2c278 David Howells 2026-01-07 18 * @orig: The original iterator d7c4f8b0f2c278 David Howells 2026-01-07 19 * @max_len: Maximum number of bytes to extract d7c4f8b0f2c278 David Howells 2026-01-07 20 * @max_pages: Maximum number of pages to extract d7c4f8b0f2c278 David Howells 2026-01-07 21 * @fpos: Starting file position to label the bvecq with d7c4f8b0f2c278 David Howells 2026-01-07 22 * @_bvecq_head: Where to cache the bvec queue d7c4f8b0f2c278 David Howells 2026-01-07 23 * @extraction_flags: Flags to qualify the request d7c4f8b0f2c278 David Howells 2026-01-07 24 * d7c4f8b0f2c278 David Howells 2026-01-07 25 * Extract virtually contiguous page fragments from the source iterator up to d7c4f8b0f2c278 David Howells 2026-01-07 26 * the given maxima and build bvec queue that refers to all of those bits. d7c4f8b0f2c278 David Howells 2026-01-07 27 * This allows the original iterator to disposed of. d7c4f8b0f2c278 David Howells 2026-01-07 28 * d7c4f8b0f2c278 David Howells 2026-01-07 29 * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be d7c4f8b0f2c278 David Howells 2026-01-07 30 * allowed on the pages extracted. d7c4f8b0f2c278 David Howells 2026-01-07 31 * d7c4f8b0f2c278 David Howells 2026-01-07 32 * On success or partial success, the amount of data in the bvec is returned, d7c4f8b0f2c278 David Howells 2026-01-07 33 * the original iterator will have been advanced by the amount extracted. d7c4f8b0f2c278 David Howells 2026-01-07 34 * d7c4f8b0f2c278 David Howells 2026-01-07 35 * If an error occurs and no pages are extracted, an error will be returned and d7c4f8b0f2c278 David Howells 2026-01-07 36 * any allocated bvecq will be freed. If there is no data to be extracted (or d7c4f8b0f2c278 David Howells 2026-01-07 37 * @max_len or @max_pages are zero), a single empty bvecq will be returned. d7c4f8b0f2c278 David Howells 2026-01-07 38 * d7c4f8b0f2c278 David Howells 2026-01-07 39 * The bvecq segments are marked with indications on how to get clean up the d7c4f8b0f2c278 David Howells 2026-01-07 40 * extracted fragments. d7c4f8b0f2c278 David Howells 2026-01-07 41 */ d7c4f8b0f2c278 David Howells 2026-01-07 42 ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages, d7c4f8b0f2c278 David Howells 2026-01-07 43 unsigned long long fpos, struct bvecq **_bvecq_head, d7c4f8b0f2c278 David Howells 2026-01-07 44 iov_iter_extraction_t extraction_flags) d7c4f8b0f2c278 David Howells 2026-01-07 45 { d7c4f8b0f2c278 David Howells 2026-01-07 46 struct bvecq *bq_tail = NULL, *bq; d7c4f8b0f2c278 David Howells 2026-01-07 47 ssize_t ret = 0; d7c4f8b0f2c278 David Howells 2026-01-07 48 size_t extracted = 0; d7c4f8b0f2c278 David Howells 2026-01-07 49 d7c4f8b0f2c278 David Howells 2026-01-07 50 _enter("{%u,%zx},%zx", orig->iter_type, orig->count, max_len); d7c4f8b0f2c278 David Howells 2026-01-07 51 d7c4f8b0f2c278 David Howells 2026-01-07 52 *_bvecq_head = NULL; d7c4f8b0f2c278 David Howells 2026-01-07 53 if (max_len > orig->count) d7c4f8b0f2c278 David Howells 2026-01-07 54 max_len = orig->count; d7c4f8b0f2c278 David Howells 2026-01-07 55 if (WARN_ON_ONCE(!max_len || !max_pages)) d7c4f8b0f2c278 David Howells 2026-01-07 56 goto alloc_empty; d7c4f8b0f2c278 David Howells 2026-01-07 57 d7c4f8b0f2c278 David Howells 2026-01-07 58 max_pages = iov_iter_npages(orig, max_pages); d7c4f8b0f2c278 David Howells 2026-01-07 59 if (!max_pages) d7c4f8b0f2c278 David Howells 2026-01-07 60 goto alloc_empty; d7c4f8b0f2c278 David Howells 2026-01-07 61 d7c4f8b0f2c278 David Howells 2026-01-07 62 do { d7c4f8b0f2c278 David Howells 2026-01-07 63 bq = bvecq_alloc_one(max_pages, GFP_NOFS); d7c4f8b0f2c278 David Howells 2026-01-07 64 if (!bq) { d7c4f8b0f2c278 David Howells 2026-01-07 65 ret = -ENOMEM; d7c4f8b0f2c278 David Howells 2026-01-07 66 break; d7c4f8b0f2c278 David Howells 2026-01-07 67 } d7c4f8b0f2c278 David Howells 2026-01-07 68 if (user_backed_iter(orig)) d7c4f8b0f2c278 David Howells 2026-01-07 69 bq->mem_type = iov_iter_extract_will_pin(orig) ? d7c4f8b0f2c278 David Howells 2026-01-07 70 BVECQ_MEM_GUP : BVECQ_MEM_PAGECACHE; d7c4f8b0f2c278 David Howells 2026-01-07 71 bq->fpos = fpos + extracted; d7c4f8b0f2c278 David Howells 2026-01-07 72 d7c4f8b0f2c278 David Howells 2026-01-07 73 if (bq_tail) d7c4f8b0f2c278 David Howells 2026-01-07 74 bvecq_append(bq_tail, bq); d7c4f8b0f2c278 David Howells 2026-01-07 75 else d7c4f8b0f2c278 David Howells 2026-01-07 76 *_bvecq_head = bq; d7c4f8b0f2c278 David Howells 2026-01-07 77 bq_tail = bq; d7c4f8b0f2c278 David Howells 2026-01-07 78 d7c4f8b0f2c278 David Howells 2026-01-07 79 if (max_len == 0) d7c4f8b0f2c278 David Howells 2026-01-07 80 break; d7c4f8b0f2c278 David Howells 2026-01-07 81 d7c4f8b0f2c278 David Howells 2026-01-07 82 struct bio_vec *bv = bq->bv; d7c4f8b0f2c278 David Howells 2026-01-07 83 unsigned int slot = 0; d7c4f8b0f2c278 David Howells 2026-01-07 84 do { d7c4f8b0f2c278 David Howells 2026-01-07 85 struct page **pages; d7c4f8b0f2c278 David Howells 2026-01-07 86 ssize_t got; d7c4f8b0f2c278 David Howells 2026-01-07 87 size_t offset; d7c4f8b0f2c278 David Howells 2026-01-07 88 size_t space = bq->max_slots - slot; d7c4f8b0f2c278 David Howells 2026-01-07 89 size_t bv_size = array_size(bq->max_slots, sizeof(*bv)); d7c4f8b0f2c278 David Howells 2026-01-07 90 size_t pg_size = array_size(space, sizeof(*pages)); d7c4f8b0f2c278 David Howells 2026-01-07 91 d7c4f8b0f2c278 David Howells 2026-01-07 92 /* Put the page list at the end of the bvec list d7c4f8b0f2c278 David Howells 2026-01-07 93 * storage. bvec elements are larger than page d7c4f8b0f2c278 David Howells 2026-01-07 94 * pointers, so as long as we work 0->last, we should d7c4f8b0f2c278 David Howells 2026-01-07 95 * be fine. d7c4f8b0f2c278 David Howells 2026-01-07 96 */ d7c4f8b0f2c278 David Howells 2026-01-07 97 pages = (void *)bv + bv_size - pg_size; d7c4f8b0f2c278 David Howells 2026-01-07 98 d7c4f8b0f2c278 David Howells 2026-01-07 99 got = iov_iter_extract_pages(orig, &pages, max_len, d7c4f8b0f2c278 David Howells 2026-01-07 100 min(space, max_pages), d7c4f8b0f2c278 David Howells 2026-01-07 101 extraction_flags, &offset); d7c4f8b0f2c278 David Howells 2026-01-07 102 if (got < 0) { d7c4f8b0f2c278 David Howells 2026-01-07 103 ret = got; d7c4f8b0f2c278 David Howells 2026-01-07 104 goto out; d7c4f8b0f2c278 David Howells 2026-01-07 105 } d7c4f8b0f2c278 David Howells 2026-01-07 106 d7c4f8b0f2c278 David Howells 2026-01-07 107 if (got == 0) { d7c4f8b0f2c278 David Howells 2026-01-07 108 pr_err("extract_pages gave nothing from %zu, %zu\n", d7c4f8b0f2c278 David Howells 2026-01-07 109 extracted, max_len); d7c4f8b0f2c278 David Howells 2026-01-07 110 ret = -EIO; d7c4f8b0f2c278 David Howells 2026-01-07 111 goto out; d7c4f8b0f2c278 David Howells 2026-01-07 112 } d7c4f8b0f2c278 David Howells 2026-01-07 113 d7c4f8b0f2c278 David Howells 2026-01-07 114 if (WARN(got > max_len, d7c4f8b0f2c278 David Howells 2026-01-07 115 "%s: extract_pages overrun %zd > %zu bytes\n", d7c4f8b0f2c278 David Howells 2026-01-07 116 __func__, got, max_len)) { d7c4f8b0f2c278 David Howells 2026-01-07 117 ret = -EIO; d7c4f8b0f2c278 David Howells 2026-01-07 118 goto out; d7c4f8b0f2c278 David Howells 2026-01-07 119 } d7c4f8b0f2c278 David Howells 2026-01-07 120 d7c4f8b0f2c278 David Howells 2026-01-07 121 extracted += got; d7c4f8b0f2c278 David Howells 2026-01-07 122 max_len -= got; d7c4f8b0f2c278 David Howells 2026-01-07 123 d7c4f8b0f2c278 David Howells 2026-01-07 124 do { d7c4f8b0f2c278 David Howells 2026-01-07 125 size_t len = umin(got, PAGE_SIZE - offset); d7c4f8b0f2c278 David Howells 2026-01-07 126 d7c4f8b0f2c278 David Howells 2026-01-07 127 BUG_ON(slot >= bq->max_slots); d7c4f8b0f2c278 David Howells 2026-01-07 128 d7c4f8b0f2c278 David Howells 2026-01-07 129 bvec_set_page(&bq->bv[slot], *pages++, len, offset); d7c4f8b0f2c278 David Howells 2026-01-07 130 slot++; d7c4f8b0f2c278 David Howells 2026-01-07 131 max_pages--; d7c4f8b0f2c278 David Howells 2026-01-07 132 got -= len; d7c4f8b0f2c278 David Howells 2026-01-07 133 offset = 0; d7c4f8b0f2c278 David Howells 2026-01-07 134 } while (got > 0); d7c4f8b0f2c278 David Howells 2026-01-07 135 d7c4f8b0f2c278 David Howells 2026-01-07 136 bvecq_filled_to(bq, slot); d7c4f8b0f2c278 David Howells 2026-01-07 @137 } while (max_len > 0 && max_pages > 0 && !bvecq_is_full(bq)); d7c4f8b0f2c278 David Howells 2026-01-07 138 d7c4f8b0f2c278 David Howells 2026-01-07 139 } while (max_len > 0 && max_pages > 0); d7c4f8b0f2c278 David Howells 2026-01-07 140 d7c4f8b0f2c278 David Howells 2026-01-07 141 out: d7c4f8b0f2c278 David Howells 2026-01-07 142 if (extracted || ret == 0) d7c4f8b0f2c278 David Howells 2026-01-07 143 return extracted; d7c4f8b0f2c278 David Howells 2026-01-07 144 bvecq_put(*_bvecq_head); d7c4f8b0f2c278 David Howells 2026-01-07 145 *_bvecq_head = NULL; d7c4f8b0f2c278 David Howells 2026-01-07 146 return ret; d7c4f8b0f2c278 David Howells 2026-01-07 147 d7c4f8b0f2c278 David Howells 2026-01-07 148 alloc_empty: d7c4f8b0f2c278 David Howells 2026-01-07 149 bq = bvecq_alloc_one(1, GFP_NOFS); d7c4f8b0f2c278 David Howells 2026-01-07 150 if (!bq) d7c4f8b0f2c278 David Howells 2026-01-07 151 return -ENOMEM; d7c4f8b0f2c278 David Howells 2026-01-07 152 *_bvecq_head = bq; d7c4f8b0f2c278 David Howells 2026-01-07 153 return 0; d7c4f8b0f2c278 David Howells 2026-01-07 154 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki