Hello Kent Overstreet,
The patch 1c6fdbd8f246: "bcachefs: Initial commit" from Mar 16, 2017
(linux-next), leads to the following Smatch static checker warning:
fs/bcachefs/btree_io.c:1672 bch2_btree_node_read() potential NULL container_of
'bio'
fs/bcachefs/btree_io.c:2165 __bch2_btree_node_write() potential NULL
container_of 'bio_alloc_bioset()'
fs/bcachefs/ec.c:734 ec_block_io() potential NULL container_of
'bio_alloc_bioset()'
fs/bcachefs/fs-io-buffered.c:489 bch2_writepage_io_alloc() potential NULL
container_of 'bio_alloc_bioset()'
fs/bcachefs/fs-io.c:81 bch2_inode_flush_nocow_writes_async() potential NULL
container_of 'bio_alloc_bioset()'
fs/bcachefs/io_write.c:407 bch2_submit_wbio_replicas() potential NULL
container_of 'bio_alloc_clone()'
fs/bcachefs/fs-io-direct.c:622 bch2_direct_write() potential NULL container_of
'bio'
fs/bcachefs/btree_io.c
1628 void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
1629 bool sync)
1630 {
1631 struct bch_fs *c = trans->c;
1632 struct extent_ptr_decoded pick;
1633 struct btree_read_bio *rb;
1634 struct bch_dev *ca;
1635 struct bio *bio;
1636 int ret;
1637
1638 trace_and_count(c, btree_node_read, trans, b);
1639
1640 if (bch2_verify_all_btree_replicas &&
1641 !btree_node_read_all_replicas(c, b, sync))
1642 return;
1643
1644 ret = bch2_bkey_pick_read_device(c, bkey_i_to_s_c(&b->key),
1645 NULL, &pick);
1646
1647 if (ret <= 0) {
1648 struct printbuf buf = PRINTBUF;
1649
1650 prt_str(&buf, "btree node read error: no device to
read from\n at ");
1651 bch2_btree_pos_to_text(&buf, c, b);
1652 bch_err(c, "%s", buf.buf);
1653
1654 if (c->recovery_passes_explicit &
BIT_ULL(BCH_RECOVERY_PASS_check_topology) &&
1655 c->curr_recovery_pass >
BCH_RECOVERY_PASS_check_topology)
1656 bch2_fatal_error(c);
1657
1658 set_btree_node_read_error(b);
1659 clear_btree_node_read_in_flight(b);
1660 wake_up_bit(&b->flags, BTREE_NODE_read_in_flight);
1661 printbuf_exit(&buf);
1662 return;
1663 }
1664
1665 ca = bch_dev_bkey_exists(c, pick.ptr.dev);
1666
1667 bio = bio_alloc_bioset(NULL,
^^^^^^^^^^^^^^^^^^^^^^
No check for if bio_alloc_bioset() returns NULL.
1668 buf_pages(b->data, btree_buf_bytes(b)),
1669 REQ_OP_READ|REQ_SYNC|REQ_META,
1670 GFP_NOFS,
1671 &c->btree_bio);
--> 1672 rb = container_of(bio, struct btree_read_bio, bio);
1673 rb->c = c;
1674 rb->b = b;
1675 rb->ra = NULL;
1676 rb->start_time = local_clock();
1677 rb->have_ioref = bch2_dev_get_ioref(ca, READ);
1678 rb->pick = pick;
1679 INIT_WORK(&rb->work, btree_node_read_work);
1680 bio->bi_iter.bi_sector = pick.ptr.offset;
1681 bio->bi_end_io = btree_node_read_endio;
1682 bch2_bio_map(bio, b->data, btree_buf_bytes(b));
1683
1684 if (rb->have_ioref) {
1685
this_cpu_add(ca->io_done->sectors[READ][BCH_DATA_btree],
1686 bio_sectors(bio));
1687 bio_set_dev(bio, ca->disk_sb.bdev);
1688
1689 if (sync) {
1690 submit_bio_wait(bio);
1691 bch2_latency_acct(ca, rb->start_time, READ);
1692 btree_node_read_work(&rb->work);
1693 } else {
1694 submit_bio(bio);
1695 }
1696 } else {
1697 bio->bi_status = BLK_STS_REMOVED;
1698
1699 if (sync)
1700 btree_node_read_work(&rb->work);
1701 else
1702 queue_work(c->io_complete_wq, &rb->work);
1703 }
1704 }
regards,
dan carpenter