btrfs: abort transaction in the process_one_buffer() log tree walk callback
Hello Filipe Manana,
This is a semi-automatic email about new static checker warnings.
Commit f6f79221b128 ("btrfs: abort transaction in the process_one_buffer() log tree walk callback") from Jul 16, 2025, leads to the following Smatch complaint:
fs/btrfs/tree-log.c:377 process_one_buffer() warn: variable dereferenced before check 'trans' (see line 375) fs/btrfs/tree-log.c:388 process_one_buffer() warn: variable dereferenced before check 'trans' (see line 375)
fs/btrfs/tree-log.c
374 if (wc->pin) {
375 ret = btrfs_pin_extent_for_log_replay(trans, eb);
^^^^^The patch adds a dereference
376 if (ret) {
377 if (trans)
^^^^^
And also this check which is too late.
378 btrfs_abort_transaction(trans, ret); 379 else
regards,
dan carpenter
Quoted 9 lines · Dan Carpenter
Hello Filipe Manana,
This is a semi-automatic email about new static checker warnings.
Commit
f6f79221b128("btrfs: abort transaction in theprocess_one_buffer()log tree walk callback") from Jul 16, 2025, leads to the following Smatch complaint:
Quoted 8 lines
fs/btrfs/tree-log.c:377process_one_buffer()warn: variable dereferenced before check 'trans' (see line 375)fs/btrfs/tree-log.c:388process_one_buffer()warn: variable dereferenced before check 'trans' (see line 375)
fs/btrfs/tree-log.c374 if (wc->pin) { 375 ret = btrfs_pin_extent_for_log_replay(trans, eb); ^^^^^The patch adds a dereference
False alarm. This already happened before that patch, we didn't check if wc->trans was NULL before calling btrfs_pin_extent_for_log_replay(), and that's fine because if wc->pin is true then trans is not NULL.
Thanks.
Quoted 12 lines
376 if (ret) { 377 if (trans) ^^^^^And also this check which is too late.
378 btrfs_abort_transaction(trans, ret); 379 elseregards,
dan carpenter
Quoted 19 lines · Filipe Manana
Quoted 9 lines · Dan Carpenter
Hello Filipe Manana,
This is a semi-automatic email about new static checker warnings.
Commit
f6f79221b128("btrfs: abort transaction in theprocess_one_buffer()log tree walk callback") from Jul 16, 2025, leads to the following Smatch complaint:Quoted 8 lines
fs/btrfs/tree-log.c:377process_one_buffer()warn: variable dereferenced before check 'trans' (see line 375)fs/btrfs/tree-log.c:388process_one_buffer()warn: variable dereferenced before check 'trans' (see line 375)
fs/btrfs/tree-log.c374 if (wc->pin) { 375 ret = btrfs_pin_extent_for_log_replay(trans, eb); ^^^^^The patch adds a dereference
Quoted 5 lines
False alarm. This already happened before that patch, we didn't check if
wc->transwas NULL before callingbtrfs_pin_extent_for_log_replay(), and that's fine because ifwc->pinis true then trans is not NULL.
To be honest, the deleting the NULL check is the most common way to fix a "pointless NULL check after a dereference" warning...
regards,
dan carpenter
Quoted 21 lines · Dan Carpenter
Quoted 19 lines · Filipe Manana
Quoted 17 lines · Dan Carpenter
Hello Filipe Manana,
This is a semi-automatic email about new static checker warnings.
Commit
f6f79221b128("btrfs: abort transaction in theprocess_one_buffer()log tree walk callback") from Jul 16, 2025, leads to the following Smatch complaint:
fs/btrfs/tree-log.c:377process_one_buffer()warn: variable dereferenced before check 'trans' (see line 375)fs/btrfs/tree-log.c:388process_one_buffer()warn: variable dereferenced before check 'trans' (see line 375)
fs/btrfs/tree-log.c374 if (wc->pin) { 375 ret = btrfs_pin_extent_for_log_replay(trans, eb); ^^^^^The patch adds a dereference
Quoted 8 lines
Quoted 5 lines
False alarm. This already happened before that patch, we didn't check if
wc->transwas NULL before callingbtrfs_pin_extent_for_log_replay(), and that's fine because ifwc->pinis true then trans is not NULL.To be honest, the deleting the NULL check is the most common way to fix a "pointless NULL check after a dereference" warning...
Yes, the NULL checks can be removed inside that if block.
I sent earlier a patch to remove them and it will later be folded into that commit:
Quoted 4 lines
regards,
dan carpenter