On Mon, Jul 31, 2023 at 04:57:18PM +0800, Peng Zhang wrote: > > > 在 2023/7/31 14:34, Dan Carpenter 写道: > > Hello Peng Zhang, > > > > This is a semi-automatic email about new static checker warnings. > > > > The patch d126b5d9410f: "maple_tree: make mas_validate_gaps() to > > check metadata" from Jul 11, 2023, leads to the following Smatch > > complaint: > > > > tools/testing/radix-tree/../../../lib/maple_tree.c:6989 mas_validate_gaps() > > warn: variable dereferenced before check 'gaps' (see line 6983) > > > > tools/testing/radix-tree/../../../lib/maple_tree.c > > 6982 > > 6983 if (gaps[offset] != max_gap) { > > ^^^^^ > > Dereferenced. > > > > 6984 pr_err("gap %p[%u] is not the largest gap %lu\n", > > 6985 node, offset, max_gap); > > 6986 MT_BUG_ON(mas->tree, 1); > > 6987 } > > 6988 > > 6989 MT_BUG_ON(mas->tree, !gaps); > > ^^^^^ > > Checked too late. This is pointless as well. Just delete this line. > Since this is a validator, it is only used for testing, so it will not > have any impact on normal functionality. I'm not going to delete this > line, will move it before dereferencing. Thank you for your report. It will probably still end up generating a warning because MT_BUG_ON() doesn't actually call BUG(). Smatch actually generates two warnings for this file. tools/testing/radix-tree/../../../lib/maple_tree.c:6983 mas_validate_gaps() error: we previously assumed 'gaps' could be null (see line 6950) tools/testing/radix-tree/../../../lib/maple_tree.c:6989 mas_validate_gaps() warn: variable dereferenced before check 'gaps' (see line 6983) That business of writing crappier code for the testing/ directory is a weird thing because it has to be done so specifically to not generate warnings and debate. It's sometimes easier in the end to just do it correctly. regards, dan carpenter