Skip to content

Commit

Permalink
dm btree spine: eliminate duplicate le32_to_cpu() in node_check()
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
jthornber authored and snitm committed Jan 4, 2022
1 parent 851a8cd commit e36649b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/md/persistent-data/dm-btree-spine.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int node_check(struct dm_block_validator *v,
struct node_header *h = &n->header;
size_t value_size;
__le32 csum_disk;
uint32_t flags;
uint32_t flags, nr_entries, max_entries;

if (dm_block_location(b) != le64_to_cpu(h->blocknr)) {
DMERR_LIMIT("node_check failed: blocknr %llu != wanted %llu",
Expand All @@ -53,15 +53,17 @@ static int node_check(struct dm_block_validator *v,
return -EILSEQ;
}

nr_entries = le32_to_cpu(h->nr_entries);
max_entries = le32_to_cpu(h->max_entries);
value_size = le32_to_cpu(h->value_size);

if (sizeof(struct node_header) +
(sizeof(__le64) + value_size) * le32_to_cpu(h->max_entries) > block_size) {
(sizeof(__le64) + value_size) * max_entries > block_size) {
DMERR_LIMIT("node_check failed: max_entries too large");
return -EILSEQ;
}

if (le32_to_cpu(h->nr_entries) > le32_to_cpu(h->max_entries)) {
if (nr_entries > max_entries) {
DMERR_LIMIT("node_check failed: too many entries");
return -EILSEQ;
}
Expand Down

0 comments on commit e36649b

Please sign in to comment.