btrfs: calculate number of eb pages properly in csum_tree_block
David Sterba
maintainerPATCH 1/1 btrfs: calculate number of eb pages properly in csum_tree_block
Building with -Warray-bounds on systems with 64K pages there's a warning:
fs/btrfs/disk-io.c: In function ‘csum_tree_block’:
fs/btrfs/disk-io.c:226:34: warning: array subscript 1 is above array bounds of ‘struct page *[1]’ [-Warray-bounds]
226 | kaddr = page_address(buf->pages[i]);
| ~~~~~~~~~~^~~
./include/linux/mm.h:1630:48: note: in definition of macro ‘page_address’
1630 | #define page_address(page) lowmem_page_address(page)
| ^~~~
In file included from fs/btrfs/ctree.h:32,
from fs/btrfs/disk-io.c:23:
fs/btrfs/extent_io.h:98:15: note: while referencing ‘pages’
98 | struct page *pages[1];
| ^~~~~The compiler has no way to know that in that case the nodesize is exactly PAGE_SIZE, so the resulting number of pages will be correct (1).
Let's use num_extent_pages that makes the case nodesize == PAGE_SIZE explicitly 1.
--- fs/btrfs/disk-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -1
@@ -210,7 +210,7 @@ void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb,static void csum_tree_block (struct extent_buffer *buf,u8 *result) {struct btrfs_fs_info *fs_info = buf->fs_info; -const int num_pages = fs_info->nodesize >>PAGE_SHIFT ; +const int num_pages =num_extent_pages (buf);const int first_page_part =min_t (u32,PAGE_SIZE , fs_info->nodesize);SHASH_DESC_ON_STACK (shash, fs_info->csum_shash);char *kaddr;
Signature · 1 line
2.31.1
Quoted 16 lines · David Sterba
Building with -Warray-bounds on systems with 64K pages there's a warning:
fs/btrfs/disk-io.c: In function ‘csum_tree_block’:
fs/btrfs/disk-io.c:226:34: warning: array subscript 1 is above array bounds of ‘struct page *[1]’ [-Warray-bounds]226 | kaddr = page_address(buf->pages[i]); | ~~~~~~~~~~^~~ ./include/linux/mm.h:1630:48: note: in definition of macro ‘page_address’ 1630 | #define page_address(page) lowmem_page_address(page) | ^~~~ In file included from fs/btrfs/ctree.h:32, from fs/btrfs/disk-io.c:23: fs/btrfs/extent_io.h:98:15: note: while referencing ‘pages’ 98 | struct page *pages[1]; | ^~~~~
Quoted 8 lines
The compiler has no way to know that in that case the nodesize is exactly
PAGE_SIZE, so the resulting number of pages will be correct (1).Let's use
num_extent_pagesthat makes the case nodesize ==PAGE_SIZEexplicitly 1.Reported-by Gustavo A. R. Silva <[email protected]>Signed-off-by David Sterba <[email protected]>
Thanks,
Qu
Quoted 18 lines
--- fs/btrfs/disk-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/disk-io.c +1
-1@@ -210,7 +210,7 @@ void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb,static void csum_tree_block (struct extent_buffer *buf,u8 *result) {struct btrfs_fs_info *fs_info = buf->fs_info; -const int num_pages = fs_info->nodesize >>PAGE_SHIFT ; +const int num_pages =num_extent_pages (buf);const int first_page_part =min_t (u32,PAGE_SIZE , fs_info->nodesize);SHASH_DESC_ON_STACK (shash, fs_info->csum_shash);char *kaddr;