On Mon, Feb 12, 2024 at 05:58:05PM +0100, Andrey Albershteyn wrote: > + u64 block_offset; 'hblock_pos', to make it clear that it's in bytes, and that it's for the hash block, not the data block. > + u64 ra_bytes = 0; > + u64 tree_size; > > /* > * The index of the block in the current level; also the index > @@ -105,18 +106,20 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, > /* Index of the hash block in the tree overall */ > hblock_idx = params->level_start[level] + next_hidx; > > - /* Index of the hash page in the tree overall */ > - hpage_idx = hblock_idx >> params->log_blocks_per_page; > + /* Offset of the Merkle tree block into the tree */ > + block_offset = hblock_idx << params->log_blocksize; > > /* Byte offset of the hash within the block */ > hoffset = (hidx << params->log_digestsize) & > (params->block_size - 1); > > - num_ra_pages = level == 0 ? > - min(max_ra_pages, params->tree_pages - hpage_idx) : 0; > + if (level == 0) { > + tree_size = params->tree_pages << PAGE_SHIFT; > + ra_bytes = min(max_ra_bytes, (tree_size - block_offset)); > + } How about: ra_bytes = level == 0 ? min(max_ra_bytes, params->tree_size - hblock_pos) : 0; - Eric