fs/bcachefs/snapshot.c:1149 bch2_snapshot_node_delete() warn: missing error code? 'ret'
PATCH 12911/13054 fs/bcachefs/snapshot.c:1149 bch2_snapshot_node_delete() warn: missing error code? 'ret'
tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: b9ddaa95fd283bce7041550ddbbe7e764c477110 commit: 24c5e7ab4066da2073d1c50e82308c8bc0ec4ec3 [12911/13054] bcachefs: Convert bch2_bkey_get_mut() to CLASS(btree_iter) config: parisc-randconfig-r071-20250801 (https://download.01.org/0day-ci/archive/20250802/[email protected]/config) compiler: hppa-linux-gcc (GCC) 15.1.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: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:fs/bcachefs/snapshot.c:1149 bch2_snapshot_node_delete() warn: missing error code? 'ret'
vim +/ret +1149 fs/bcachefs/snapshot.c
96dea3d599dbc3 Kent Overstreet 2023-09-12 1110 static int bch2_snapshot_node_delete(struct btree_trans *trans, u32 id)
8e877caaad8185 Kent Overstreet 2023-08-16 1111 {
8e877caaad8185 Kent Overstreet 2023-08-16 1112 struct bch_fs *c = trans->c;
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1113 u32 parent_id, child_id;
8e877caaad8185 Kent Overstreet 2023-08-16 1114 unsigned i;
8e877caaad8185 Kent Overstreet 2023-08-16 1115
e9756dd29f33ed Kent Overstreet 2025-05-02 1116 struct bkey_i_snapshot *s =
24c5e7ab4066da Kent Overstreet 2025-07-31 1117 bch2_bkey_get_mut_typed(trans, BTREE_ID_snapshots, POS(0, id), 0, snapshot);
24c5e7ab4066da Kent Overstreet 2025-07-31 1118 int ret = PTR_ERR_OR_ZERO(s);
8e877caaad8185 Kent Overstreet 2023-08-16 1119 bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c,
8e877caaad8185 Kent Overstreet 2023-08-16 1120 "missing snapshot %u", id);
8e877caaad8185 Kent Overstreet 2023-08-16 1121
8e877caaad8185 Kent Overstreet 2023-08-16 1122 if (ret)
24c5e7ab4066da Kent Overstreet 2025-07-31 1123 return ret;
8e877caaad8185 Kent Overstreet 2023-08-16 1124
e9756dd29f33ed Kent Overstreet 2025-05-02 1125 BUG_ON(BCH_SNAPSHOT_DELETED(&s->v));
e9756dd29f33ed Kent Overstreet 2025-05-02 1126 BUG_ON(s->v.children[1]);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1127
e9756dd29f33ed Kent Overstreet 2025-05-02 1128 parent_id = le32_to_cpu(s->v.parent);
e9756dd29f33ed Kent Overstreet 2025-05-02 1129 child_id = le32_to_cpu(s->v.children[0]);
8e877caaad8185 Kent Overstreet 2023-08-16 1130
8e877caaad8185 Kent Overstreet 2023-08-16 1131 if (parent_id) {
24c5e7ab4066da Kent Overstreet 2025-07-31 1132 struct bkey_i_snapshot *parent =
24c5e7ab4066da Kent Overstreet 2025-07-31 1133 bch2_bkey_get_mut_typed(trans, BTREE_ID_snapshots, POS(0, parent_id),
8e877caaad8185 Kent Overstreet 2023-08-16 1134 0, snapshot);
8e877caaad8185 Kent Overstreet 2023-08-16 1135 ret = PTR_ERR_OR_ZERO(parent);
8e877caaad8185 Kent Overstreet 2023-08-16 1136 bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c,
8e877caaad8185 Kent Overstreet 2023-08-16 1137 "missing snapshot %u", parent_id);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1138 if (unlikely(ret))
24c5e7ab4066da Kent Overstreet 2025-07-31 1139 return ret;
8e877caaad8185 Kent Overstreet 2023-08-16 1140
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1141 /* find entry in parent->children for node being deleted */
8e877caaad8185 Kent Overstreet 2023-08-16 1142 for (i = 0; i < 2; i++)
8e877caaad8185 Kent Overstreet 2023-08-16 1143 if (le32_to_cpu(parent->v.children[i]) == id)
8e877caaad8185 Kent Overstreet 2023-08-16 1144 break;
8e877caaad8185 Kent Overstreet 2023-08-16 1145
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1146 if (bch2_fs_inconsistent_on(i == 2, c,
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1147 "snapshot %u missing child pointer to %u",
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1148 parent_id, id))24c5e7ab4066da Kent Overstreet 2025-07-31 @1149 return ret;
This returns success but it looks like the intention was to return an error code.
8e877caaad8185 Kent Overstreet 2023-08-16 1150
0a11adfb7aceb6 Kent Overstreet 2023-11-11 1151 parent->v.children[i] = cpu_to_le32(child_id);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1152
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1153 normalize_snapshot_child_pointers(&parent->v);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1154 }
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1155
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1156 if (child_id) {
24c5e7ab4066da Kent Overstreet 2025-07-31 1157 struct bkey_i_snapshot *child =
24c5e7ab4066da Kent Overstreet 2025-07-31 1158 bch2_bkey_get_mut_typed(trans, BTREE_ID_snapshots, POS(0, child_id),
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1159 0, snapshot);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1160 ret = PTR_ERR_OR_ZERO(child);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1161 bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c,
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1162 "missing snapshot %u", child_id);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1163 if (unlikely(ret))
24c5e7ab4066da Kent Overstreet 2025-07-31 1164 return ret;
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1165
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1166 child->v.parent = cpu_to_le32(parent_id);
f55d6e07bc6c9b Kent Overstreet 2023-08-17 1167 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 56 lines · Dan Carpenter
tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: b9ddaa95fd283bce7041550ddbbe7e764c477110 commit: 24c5e7ab4066da2073d1c50e82308c8bc0ec4ec3 [12911/13054] bcachefs: Convert bch2_bkey_get_mut() to CLASS(btree_iter) config: parisc-randconfig-r071-20250801 (https://download.01.org/0day-ci/archive/20250802/[email protected]/config) compiler: hppa-linux-gcc (GCC) 15.1.0If 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: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/smatch warnings:
fs/bcachefs/snapshot.c:1149bch2_snapshot_node_delete()warn: missing error code? 'ret'vim +/ret +1149
fs/bcachefs/snapshot.c96dea3d599dbc3 Kent Overstreet 2023-09-12 1110 static int bch2_snapshot_node_delete(struct btree_trans *trans, u32 id) 8e877caaad8185 Kent Overstreet 2023-08-16 1111 { 8e877caaad8185 Kent Overstreet 2023-08-16 1112 struct bch_fs *c = trans->c; f55d6e07bc6c9b Kent Overstreet 2023-08-17 1113 u32 parent_id, child_id; 8e877caaad8185 Kent Overstreet 2023-08-16 1114 unsigned i; 8e877caaad8185 Kent Overstreet 2023-08-16 1115 e9756dd29f33ed Kent Overstreet 2025-05-02 1116 struct bkey_i_snapshot *s = 24c5e7ab4066da Kent Overstreet 2025-07-31 1117 bch2_bkey_get_mut_typed(trans, BTREE_ID_snapshots, POS(0, id), 0, snapshot); 24c5e7ab4066da Kent Overstreet 2025-07-31 1118 int ret = PTR_ERR_OR_ZERO(s); 8e877caaad8185 Kent Overstreet 2023-08-16 1119 bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c, 8e877caaad8185 Kent Overstreet 2023-08-16 1120 "missing snapshot %u", id); 8e877caaad8185 Kent Overstreet 2023-08-16 1121 8e877caaad8185 Kent Overstreet 2023-08-16 1122 if (ret) 24c5e7ab4066da Kent Overstreet 2025-07-31 1123 return ret; 8e877caaad8185 Kent Overstreet 2023-08-16 1124 e9756dd29f33ed Kent Overstreet 2025-05-02 1125 BUG_ON(BCH_SNAPSHOT_DELETED(&s->v)); e9756dd29f33ed Kent Overstreet 2025-05-02 1126 BUG_ON(s->v.children[1]); f55d6e07bc6c9b Kent Overstreet 2023-08-17 1127 e9756dd29f33ed Kent Overstreet 2025-05-02 1128 parent_id = le32_to_cpu(s->v.parent); e9756dd29f33ed Kent Overstreet 2025-05-02 1129 child_id = le32_to_cpu(s->v.children[0]); 8e877caaad8185 Kent Overstreet 2023-08-16 1130 8e877caaad8185 Kent Overstreet 2023-08-16 1131 if (parent_id) { 24c5e7ab4066da Kent Overstreet 2025-07-31 1132 struct bkey_i_snapshot *parent = 24c5e7ab4066da Kent Overstreet 2025-07-31 1133 bch2_bkey_get_mut_typed(trans, BTREE_ID_snapshots, POS(0, parent_id), 8e877caaad8185 Kent Overstreet 2023-08-16 1134 0, snapshot); 8e877caaad8185 Kent Overstreet 2023-08-16 1135 ret = PTR_ERR_OR_ZERO(parent); 8e877caaad8185 Kent Overstreet 2023-08-16 1136 bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c, 8e877caaad8185 Kent Overstreet 2023-08-16 1137 "missing snapshot %u", parent_id); f55d6e07bc6c9b Kent Overstreet 2023-08-17 1138 if (unlikely(ret)) 24c5e7ab4066da Kent Overstreet 2025-07-31 1139 return ret; 8e877caaad8185 Kent Overstreet 2023-08-16 1140 f55d6e07bc6c9b Kent Overstreet 2023-08-17 1141 /* find entry in parent->children for node being deleted */ 8e877caaad8185 Kent Overstreet 2023-08-16 1142 for (i = 0; i < 2; i++) 8e877caaad8185 Kent Overstreet 2023-08-16 1143 if (le32_to_cpu(parent->v.children[i]) == id) 8e877caaad8185 Kent Overstreet 2023-08-16 1144 break; 8e877caaad8185 Kent Overstreet 2023-08-16 1145 f55d6e07bc6c9b Kent Overstreet 2023-08-17 1146 if (bch2_fs_inconsistent_on(i == 2, c, f55d6e07bc6c9b Kent Overstreet 2023-08-17 1147 "snapshot %u missing child pointer to %u", f55d6e07bc6c9b Kent Overstreet 2023-08-17 1148 parent_id, id))
Quoted 4 lines
24c5e7ab4066daKent Overstreet 2025-07-31 @1149 return ret;This returns success but it looks like the intention was to return an error code.
nice catch, that's an old bug exposed by getting rid of gotos for error hnadling
It's really technically a bug; calling bch2_fs_inconsistent() does an emergency shutdown, so returning an error doesn't matter that much. But it's worth fixing, gives us cleaner error messages if anything else prints out the error.