]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: safely advance counter when looking up bio csums
authorDavid Sterba <dsterba@suse.com>
Wed, 8 Jan 2020 14:29:53 +0000 (15:29 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 20 Jan 2020 15:41:01 +0000 (16:41 +0100)
commite058c3ee2f73a05e61908b221dc3b7803db4dec6
tree7f7160042a0f956aa9df99d2f5111402196cb1cc
parentf8232ccca55aea78e8d00541f99a5922257c326d
btrfs: safely advance counter when looking up bio csums

Dan's smatch tool reports

  fs/btrfs/file-item.c:295 btrfs_lookup_bio_sums()
  warn: should this be 'count == -1'

which points to the while (count--) loop. With count == 0 the check
itself could decrement it to -1. There's a WARN_ON a few lines below
that has never been seen in practice though.

It turns out that the value of page_bytes_left matches the count (by
sectorsize multiples). The loop never reaches the state where count
would go to -1, because page_bytes_left == 0 is found first and this
breaks out.

For clarity, use only plain check on count (and only for positive
value), decrement safely inside the loop. Any other discrepancy after
the whole bio list processing should be reported by the exising
WARN_ON_ONCE as well.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file-item.c