Hello Kent Overstreet,
The patch 46be00209417: "bcachefs: Rhashtable based buckets_in_flight
for copygc" from Mar 11, 2023 (linux-next), leads to the following
Smatch static checker warning:
fs/bcachefs/movinggc.c:224 bch2_copygc()
error: 'f' dereferencing possible ERR_PTR()
fs/bcachefs/movinggc.c
190 noinline
191 static int bch2_copygc(struct btree_trans *trans,
192 struct moving_context *ctxt,
193 struct buckets_in_flight *buckets_in_flight)
194 {
195 struct bch_fs *c = trans->c;
196 struct data_update_opts data_opts = {
197 .btree_insert_flags = BCH_WATERMARK_copygc,
198 };
199 move_buckets buckets = { 0 };
200 struct move_bucket_in_flight *f;
201 struct move_bucket *i;
202 u64 moved = atomic64_read(&ctxt->stats->sectors_moved);
203 int ret = 0;
204
205 ret = bch2_copygc_get_buckets(trans, ctxt, buckets_in_flight,
&buckets);
206 if (ret)
207 goto err;
208
209 darray_for_each(buckets, i) {
210 if (unlikely(freezing(current)))
211 break;
212
213 f = move_bucket_in_flight_add(buckets_in_flight, *i);
move_bucket_in_flight_add() can return a mix of error codes such as
-E2BIG.
214 ret = PTR_ERR_OR_ZERO(f);
215 if (ret == -EEXIST) { /* rare race: copygc_get_buckets
returned same bucket more than once */
216 ret = 0;
217 continue;
218 }
219 if (ret == -ENOMEM) { /* flush IO, continue later */
220 ret = 0;
221 break;
222 }
223
--> 224 ret = __bch2_evacuate_bucket(trans, ctxt, f,
f->bucket.k.bucket,
^^^^^^^^^^^^^^^^^^
Warning.
225 f->bucket.k.gen,
data_opts);
226 if (ret)
227 goto err;
228 }
229 err:
230 darray_exit(&buckets);
231
232 /* no entries in LRU btree found, or got to end: */
233 if (bch2_err_matches(ret, ENOENT))
234 ret = 0;
235
236 if (ret < 0 && !bch2_err_matches(ret, EROFS))
237 bch_err_msg(c, ret, "from bch2_move_data()");
238
239 moved = atomic64_read(&ctxt->stats->sectors_moved) - moved;
240 trace_and_count(c, copygc, c, moved, 0, 0, 0);
241 return ret;
242 }
regards,
dan carpenter