From: Dan Carpenter <dan.carpenter@linaro.org>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcachefs@vger.kernel.org
Subject: [bug report] bcachefs: bch_err_throw()
Date: Wed, 6 Aug 2025 14:44:25 +0300 [thread overview]
Message-ID: <aJNAGQeRcXeFkaJT@stanley.mountain> (raw)
Hello Kent Overstreet,
Commit 09b9c72bd4b7 ("bcachefs: bch_err_throw()") from May 28, 2025
(linux-next), leads to the following (unpublished) Smatch static checker
warning:
fs/bcachefs/super.c:2546 bch2_fs_open()
warn: pointer dereferenced without being set 'c'
fs/bcachefs/super.c
2515 struct bch_fs *bch2_fs_open(darray_const_str *devices,
2516 struct bch_opts *opts)
2517 {
2518 bch_sb_handles sbs = {};
2519 struct bch_fs *c = NULL;
^^^^^^^^^
c is NULL
2520 struct bch_sb_handle *best = NULL;
2521 int ret = 0;
2522
2523 if (!try_module_get(THIS_MODULE))
2524 return ERR_PTR(-ENODEV);
2525
2526 if (!devices->nr) {
2527 ret = -EINVAL;
2528 goto err;
2529 }
2530
2531 ret = darray_make_room(&sbs, devices->nr);
2532 if (ret)
2533 goto err;
2534
2535 darray_for_each(*devices, i) {
2536 struct bch_sb_handle sb = { NULL };
2537
2538 ret = bch2_read_super(*i, opts, &sb);
2539 if (ret)
2540 goto err;
2541
2542 BUG_ON(darray_push(&sbs, sb));
2543 }
2544
2545 if (opts->nochanges && !opts->read_only) {
--> 2546 ret = bch_err_throw(c, erofs_nochanges);
^
It hasn't been set yet.
2547 goto err_print;
2548 }
2549
2550 darray_for_each(sbs, sb)
2551 if (!best || sb_cmp(sb->sb, best->sb) > 0)
2552 best = sb;
2553
2554 darray_for_each_reverse(sbs, sb) {
2555 ret = bch2_dev_in_fs(best, sb, opts);
2556
2557 if (ret == -BCH_ERR_device_has_been_removed ||
2558 ret == -BCH_ERR_device_splitbrain) {
2559 bch2_free_super(sb);
2560 darray_remove_item(&sbs, sb);
2561 best -= best > sb;
2562 ret = 0;
2563 continue;
2564 }
2565
2566 if (ret)
2567 goto err_print;
2568 }
2569
2570 c = bch2_fs_alloc(best->sb, opts, &sbs);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
set here.
2571 ret = PTR_ERR_OR_ZERO(c);
2572 if (ret)
2573 goto err;
2574
2575 scoped_guard(rwsem_write, &c->state_lock)
2576 darray_for_each(sbs, sb) {
2577 ret = bch2_dev_attach_bdev(c, sb);
2578 if (ret)
2579 goto err;
2580 }
2581
2582 if (!c->opts.nostart) {
2583 ret = bch2_fs_start(c);
2584 if (ret)
2585 goto err;
2586 }
2587 out:
2588 darray_for_each(sbs, sb)
2589 bch2_free_super(sb);
2590 darray_exit(&sbs);
2591 module_put(THIS_MODULE);
2592 return c;
2593 err_print:
2594 pr_err("bch_fs_open err opening %s: %s",
2595 devices->data[0], bch2_err_str(ret));
2596 err:
2597 if (!IS_ERR_OR_NULL(c))
2598 bch2_fs_stop(c);
2599 c = ERR_PTR(ret);
2600 goto out;
2601 }
regards,
dan carpenter
next reply other threads:[~2025-08-06 11:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 11:44 Dan Carpenter [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-08-06 11:44 [bug report] bcachefs: bch_err_throw() Dan Carpenter
2025-08-06 17:02 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aJNAGQeRcXeFkaJT@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox