btrfs: use PAGE_ALIGNED instead of open-coding it
[sfrench/cifs-2.6.git] / fs / btrfs / check-integrity.c
index 2e43fba4403566bd2393a9319821bda2924e9418..84e9729badaa72f43b8ac9939ceeae6c17deb974 100644 (file)
@@ -1202,24 +1202,24 @@ static void btrfsic_read_from_block_data(
        void *dstv, u32 offset, size_t len)
 {
        size_t cur;
-       size_t offset_in_page;
+       size_t pgoff;
        char *kaddr;
        char *dst = (char *)dstv;
-       size_t start_offset = block_ctx->start & ((u64)PAGE_SIZE - 1);
+       size_t start_offset = offset_in_page(block_ctx->start);
        unsigned long i = (start_offset + offset) >> PAGE_SHIFT;
 
        WARN_ON(offset + len > block_ctx->len);
-       offset_in_page = (start_offset + offset) & (PAGE_SIZE - 1);
+       pgoff = offset_in_page(start_offset + offset);
 
        while (len > 0) {
-               cur = min(len, ((size_t)PAGE_SIZE - offset_in_page));
+               cur = min(len, ((size_t)PAGE_SIZE - pgoff));
                BUG_ON(i >= DIV_ROUND_UP(block_ctx->len, PAGE_SIZE));
                kaddr = block_ctx->datav[i];
-               memcpy(dst, kaddr + offset_in_page, cur);
+               memcpy(dst, kaddr + pgoff, cur);
 
                dst += cur;
                len -= cur;
-               offset_in_page = 0;
+               pgoff = 0;
                i++;
        }
 }
@@ -1601,7 +1601,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
        BUG_ON(block_ctx->datav);
        BUG_ON(block_ctx->pagev);
        BUG_ON(block_ctx->mem_to_free);
-       if (block_ctx->dev_bytenr & ((u64)PAGE_SIZE - 1)) {
+       if (!PAGE_ALIGNED(block_ctx->dev_bytenr)) {
                pr_info("btrfsic: read_block() with unaligned bytenr %llu\n",
                       block_ctx->dev_bytenr);
                return -1;
@@ -1720,7 +1720,7 @@ static int btrfsic_test_for_metadata(struct btrfsic_state *state,
        num_pages = state->metablock_size >> PAGE_SHIFT;
        h = (struct btrfs_header *)datav[0];
 
-       if (memcmp(h->fsid, fs_info->fsid, BTRFS_FSID_SIZE))
+       if (memcmp(h->fsid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE))
                return 1;
 
        for (i = 0; i < num_pages; i++) {
@@ -1778,7 +1778,7 @@ again:
                                return;
                        }
                        is_metadata = 1;
-                       BUG_ON(BTRFS_SUPER_INFO_SIZE & (PAGE_SIZE - 1));
+                       BUG_ON(!PAGE_ALIGNED(BTRFS_SUPER_INFO_SIZE));
                        processed_len = BTRFS_SUPER_INFO_SIZE;
                        if (state->print_mask &
                            BTRFSIC_PRINT_MASK_TREE_BEFORE_SB_WRITE) {
@@ -2892,12 +2892,12 @@ int btrfsic_mount(struct btrfs_fs_info *fs_info,
        struct list_head *dev_head = &fs_devices->devices;
        struct btrfs_device *device;
 
-       if (fs_info->nodesize & ((u64)PAGE_SIZE - 1)) {
+       if (!PAGE_ALIGNED(fs_info->nodesize)) {
                pr_info("btrfsic: cannot handle nodesize %d not being a multiple of PAGE_SIZE %ld!\n",
                       fs_info->nodesize, PAGE_SIZE);
                return -1;
        }
-       if (fs_info->sectorsize & ((u64)PAGE_SIZE - 1)) {
+       if (!PAGE_ALIGNED(fs_info->sectorsize)) {
                pr_info("btrfsic: cannot handle sectorsize %d not being a multiple of PAGE_SIZE %ld!\n",
                       fs_info->sectorsize, PAGE_SIZE);
                return -1;