dm verity fec: fix misaligned RS roots IO
[linux-2.6-microblaze.git] / drivers / md / dm-verity-fec.c
index 66f4c63..cea2b37 100644 (file)
@@ -65,7 +65,7 @@ static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
        u8 *res;
 
        position = (index + rsb) * v->fec->roots;
-       block = div64_u64_rem(position, v->fec->roots << SECTOR_SHIFT, &rem);
+       block = div64_u64_rem(position, v->fec->io_size, &rem);
        *offset = (unsigned)rem;
 
        res = dm_bufio_read(v->fec->bufio, block, buf);
@@ -154,7 +154,7 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio,
 
                /* read the next block when we run out of parity bytes */
                offset += v->fec->roots;
-               if (offset >= v->fec->roots << SECTOR_SHIFT) {
+               if (offset >= v->fec->io_size) {
                        dm_bufio_release(buf);
 
                        par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
@@ -742,8 +742,13 @@ int verity_fec_ctr(struct dm_verity *v)
                return -E2BIG;
        }
 
+       if ((f->roots << SECTOR_SHIFT) & ((1 << v->data_dev_block_bits) - 1))
+               f->io_size = 1 << v->data_dev_block_bits;
+       else
+               f->io_size = v->fec->roots << SECTOR_SHIFT;
+
        f->bufio = dm_bufio_client_create(f->dev->bdev,
-                                         f->roots << SECTOR_SHIFT,
+                                         f->io_size,
                                          1, 0, NULL, NULL);
        if (IS_ERR(f->bufio)) {
                ti->error = "Cannot initialize FEC bufio client";